[JBoss JIRA] (HIBERNATE-171) property ordering in DDL when using schema generation
by nimo stephan (Jira)
nimo stephan created HIBERNATE-171:
--------------------------------------
Summary: property ordering in DDL when using schema generation
Key: HIBERNATE-171
URL: https://issues.jboss.org/browse/HIBERNATE-171
Project: Hibernate Integration
Issue Type: Enhancement
Reporter: nimo stephan
Assignee: Steve Ebersole
Would be nice to have a new jpa/hibernate annotation to define the ordering within an ddl schema generation on an entity class:
{code:java}
@Entity
@Table(name = "users")
// jpa schema generation will use the following property order when creating DDL
@TablePropertyOrder(value = {
"idUser",
"username",
"email"})
public class User {
..}
{code}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
6 years, 8 months
[JBoss JIRA] (HIBERNATE-170) Support "TIMESTAMP WITH TIME ZONE" for OffsetDateTime and ZonedDateTime
by nimo stephan (Jira)
[ https://issues.jboss.org/browse/HIBERNATE-170?page=com.atlassian.jira.plu... ]
nimo stephan edited comment on HIBERNATE-170 at 10/27/19 4:01 AM:
------------------------------------------------------------------
I guess, a simpler solution would be to use the correct columnDefinition for OffsetDateTime and ZonedDateTime by default. Actually, user must manually put columnDefinition = "TIMESTAMP WITH TIME ZONE" to add the offset of OffsetDateTime. But if db supports it, hibernate can add the correct columnDefinition by default. Actually it uses for all types of java dates the columnDefinition of "TIMESTAMP" which is not correct for OffsetDateTime and ZonedDateTime.
{code:java}
// user must add columnDefinition manually,
// would be better if Hibernate uses this columnDefinition by default if database supports it
@Column(name = "timestamp", columnDefinition = "TIMESTAMP WITH TIME ZONE")
private OffsetDateTime timestamp;
{code}
was (Author: nimo22):
I guess, a simpler solution would be to use the correct columnDefinition for OffsetDateTime and ZonedDateTime by default. Actually, user must manually put columnDefinition = "TIMESTAMP WITH TIME ZONE" to add the offset of OffsetDateTime. But if db supports it, hibernate can add the correct columnDefinition by default. Actually it uses for all types of java dates the columnDefinition of "TIMESTAMP" which is not correct for OffsetDateTime and ZonedDateTime.
{code:java}
@Column(name = "timestamp", columnDefinition = "TIMESTAMP WITH TIME ZONE")
private OffsetDateTime timestamp;
{code}
> Support "TIMESTAMP WITH TIME ZONE" for OffsetDateTime and ZonedDateTime
> -----------------------------------------------------------------------
>
> Key: HIBERNATE-170
> URL: https://issues.jboss.org/browse/HIBERNATE-170
> Project: Hibernate Integration
> Issue Type: Enhancement
> Reporter: nimo stephan
> Assignee: Steve Ebersole
> Priority: Major
>
> Something like this is supported in JPA 2.2:
> {code:java}
> @Column(name = "timestamp")
> private OffsetDateTime timestamp;
> {code}
> However, the offset is NOT persisted in the database even if the database could support it. For example, when using H2 database, then Hibernate could map this "OffsetDateTime" to the sql datatype "TIMESTAMP WITH TIME ZONE" (because H2 supports it) instead of the datatype "TIMESTAMP".
> Actually, user assumes that when using "OffsetDateTime" with JPA Annotation, JPA maps the offset as well. But this is not the case. Hibernate could also integrate a fallback for databases which does NOT support "TIMESTAMP WITH TIME ZONE". On schema generation, it could create and store something like "OffsetDateTime" or "ZonedDateTime" into two columns to avoid this manual mapping:
> {code:java}
> @Column(name = "created_on")
> private Instant timestamp;
> @Column(name = "display_offset")
> private int offset;
> {code}
> Hibernate can make use of its own "HibernateCompositeType" to store one property (OffsetDateTime) into two sql columns (timestamp and offset).
> With the solution above (by using either "TIMESTAMP WITH TIME ZONE" or the fallback), Hibernate/JPA could map the "OffsetDateTime" and "ZonedDateTime" correctly and completely with an offset or timezone.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
6 years, 8 months