|
|
|
|
|
|
When i create an entity, and generate with the hibernate.hbm2ddl.auto in my persistence.xml, The "OffsetDateTime" is not "timestamp" format.
Even when manually creating the table with "timestamp", and to execute some 'insert', or 'select', an error occurs in the conversion of "OffsetDateTime".
I noticed some odd behavior, with the "TimeOffset" also, the time zone does not seem to work properly, in conversation with the database.
*My settings to exemplify.*
JDK8_u60 + WildFly-10.0.0.CR4 + hibernate-core 5.0.1 + hibernate-entitymanager 5.0.1 + hibernate-java8 5.0.1 + postgresql-9.4-1204-jdbc42 + PostgreSQL 9.4.5 - (timestamp=UTC)
{code:java|title=TestEntity.java} @Entity @Table(name="TEST_ENTITY") public static class TestEntity { @Id @SequenceGenerator(name = "TEST_ENTITY_SEQ", sequenceName = "TEST_SEQ", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TEST_ENTITY_SEQ") @Column(name = "ID") private Long id; @Version private Long myVersion;
private LocalDateTime myLocalDateTime = LocalDateTime.now(); private LocalDate myLocalDate = LocalDate.now(); private LocalTime myLocalTime = LocalTime.now(); private Instant myInstant = Instant.now(); private ZonedDateTime myZonedDateTime = ZonedDateTime.now(); private OffsetDateTime myOffsetDateTime = OffsetDateTime.now(); private OffsetTime myOffsetTime = OffsetTime.now(); private Duration myDuration = Duration.of(20, ChronoUnit.DAYS);
public TestEntity() { } ... ... ... {code}
{code:xml|title=persitence.xml} <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="MyServicePU" transaction-type="JTA"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <jta-data-source>java:jboss/datasources/MyServiceDS</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties> <!--An SQL dialect for Postgres 9.4 and later.--> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence> {code}
Definition of JTA connection, with the database.
{code:xml|title=standalone.xml} <subsystem xmlns="urn:jboss:domain:datasources:4.0"> <datasources> <datasource jndi-name="java:jboss/datasources/MyServiceDS" pool-name="MyServiceDS" enabled="true" use-java-context="true"> <connection-url>jdbc:postgresql://192.168.1.111:5432/my_database</connection-url> <driver>postgresql</driver> <security> <user-name>test_user</user-name> <password>test_user</password> </security> <validation> <check-valid-connection-sql>SELECT 1</check-valid-connection-sql> <validate-on-match>true</validate-on-match> <background-validation>false</background-validation> </validation> </datasource> <drivers> <driver name="postgresql" module="org.postgresql"> <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class> </driver> </drivers> </datasources> </subsystem> {code}
Configuration of the module for wildfly to initialize. {code:xml|title=module.xml} <?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql"> <resources> <resource-root path="postgresql-9.4-1204-jdbc42.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module> {code}
after starting the application server.
INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 4) HHH000228: Running hbm2ddl schema update
In my database postgresql 9.4.5 the table looks like this. {code:sql|title=Table} TABLE TEST_ENTITY ( id bigint NOT NULL, myversion bigint, myduration bigint, myinstant timestamp without time zone, mylocaldate date, mylocaldatetime timestamp without time zone, mylocaltime time without time zone, myoffsetdatetime character varying(255), myoffsettime time without time zone, myzoneddatetime timestamp without time zone ) {code}
*offsetdatetime* is with "character varying(255)" {color:red} -----> myoffsetdatetime character varying(255) {color}
If i change to "time without time zone" or "time with time zone", It does not work.
The generation of the columns is equals the "without time timestamp zone", but I think the "offset" columns and "zoned" columns, should be "timestamp with time zone", and that during the conversion to the database, will automatically convert the time zone.
example: UTC -02(app) <---------> UTC+00(database)
editing...
|
|
|
|
|
|