<hibernate.version>5.0.11.Final</hibernate.version>
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
<junit.version>4.12</junit.version>
- <slf4j.version>1.7.13</slf4j.version>
+ <slf4j.version>1.7.22</slf4j.version>
</properties>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>de.juplo.yourshouter.api</groupId>
+ <artifactId>data-model</artifactId>
+ <version>1.5.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
import de.juplo.jpa.converters.TimeConversions.FixedZoneIdStrategy;
import de.juplo.jpa.converters.TimeConversions.FixedZoneOffsetStrategy;
+import de.juplo.yourshouter.api.model.Date;
+import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
ZonedDateTime zdt = ZonedDateTime.now();
OffsetDateTime odt = OffsetDateTime.now();
+ LocalDate ld = LocalDate.now();
ZoneId defaultZone = ZoneId.systemDefault();
ZoneId otherZone = defaultZone.getId().equals("America/New_York") ? ZoneId.of("Europe/Berlin") : ZoneId.of("America/New_York");
}
+ @Test
+ public void testDataModel()
+ {
+ em = Persistence.createEntityManagerFactory("data-model").createEntityManager();
+ Date date;
+
+ TimeConversions.setZoneIdStrategy(new FixedZoneIdStrategy(defaultZone));
+ date = new Date();
+ date.setId("TEST");
+ date.setDate(ld);
+ date.setStart(zdt);
+ date.setEnd(zdt);
+ persist(date);
+ date = retrieve(Date.class, date.getId());
+ assertEquals(ld, date.getDate());
+ assertEquals(zdt, date.getStart());
+ assertEquals(zdt, date.getEnd());
+ }
+
+
private void persist(Object entity)
{
EntityTransaction tx = em.getTransaction();
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-mappings
+ xmlns="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_1.xsd"
+ version="2.1">
+
+ <package>de.juplo.yourshouter.api.model</package>
+ <entity class="Date">
+ <discriminator-value>17</discriminator-value>
+ <attributes>
+ <transient name="event"/>
+ <transient name="location"/>
+ <transient name="subunit"/>
+ <transient name="contributors"/>
+ <transient name="emails"/>
+ <transient name="links"/>
+ <transient name="numbers"/>
+ <transient name="media"/>
+ <transient name="prices"/>
+ </attributes>
+ </entity>
+
+</entity-mappings>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-mappings
+ xmlns="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_1.xsd"
+ version="2.1">
+
+ <package>de.juplo.yourshouter.api.model</package>
+ <converter class="de.juplo.jpa.converters.ZonedDateTimeConverter" auto-apply="true"/>
+ <converter class="de.juplo.jpa.converters.LocalDateConverter" auto-apply="true"/>
+ <mapped-superclass class="Node" access="FIELD">
+ <inheritance strategy="SINGLE_TABLE"/>
+ <discriminator-column discriminator-type="INTEGER"/>
+ <attributes>
+ <id name="id"/>
+ <transient name="features"/>
+ <transient name="fields"/>
+ <transient name="nodes"/>
+ </attributes>
+ </mapped-superclass>
+
+</entity-mappings>
</properties>
</persistence-unit>
+ <persistence-unit name="data-model">
+ <description>Example, taken from the data-model package</description>
+ <mapping-file>META-INF/node.xml</mapping-file>
+ <mapping-file>META-INF/date.xml</mapping-file>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+ <properties>
+ <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
+ <property name="javax.persistence.jdbc.user" value="sa"/>
+ <property name="javax.persistence.jdbc.password" value=""/>
+ <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
+ <property name="hibernate.hbm2ddl.auto" value="create"/>
+ <property name="hibernate.show_sql" value="true"/>
+ </properties>
+ </persistence-unit>
+
</persistence>