diff --git a/persistence-modules/java-jpa/pom.xml b/persistence-modules/java-jpa/pom.xml
index ddab51a2e2..fa47d6bd9c 100644
--- a/persistence-modules/java-jpa/pom.xml
+++ b/persistence-modules/java-jpa/pom.xml
@@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
java-jpa
- java-jpa
-
+ java-jpa
+
parent-modules
com.baeldung
@@ -24,10 +24,34 @@
h2
${h2.version}
+
+
+
+ javax.persistence
+ javax.persistence-api
+ 2.2
+
+
+
+
+ org.eclipse.persistence
+ eclipselink
+ ${eclipselink.version}
+ runtime
+
+
+ org.postgresql
+ postgresql
+ ${postgres.version}
+ runtime
+
- 5.3.1.Final
+ 5.4.0.Final
1.4.197
+ 2.7.4-RC1
+ 42.2.5
+
\ No newline at end of file
diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/DateTimeEntityRepository.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/DateTimeEntityRepository.java
new file mode 100644
index 0000000000..0bd04da221
--- /dev/null
+++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/DateTimeEntityRepository.java
@@ -0,0 +1,68 @@
+package com.baeldung.jpa.datetime;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.time.*;
+import java.util.Calendar;
+
+public class DateTimeEntityRepository {
+ private EntityManagerFactory emf = null;
+
+ public DateTimeEntityRepository() {
+ emf = Persistence.createEntityManagerFactory("java8-datetime-postgresql");
+ }
+
+ public JPA22DateTimeEntity find(Long id) {
+ EntityManager entityManager = emf.createEntityManager();
+
+ JPA22DateTimeEntity dateTimeTypes = entityManager.find(JPA22DateTimeEntity.class, id);
+
+ entityManager.close();
+ return dateTimeTypes;
+ }
+
+ public void save(Long id) {
+ JPA22DateTimeEntity dateTimeTypes = new JPA22DateTimeEntity();
+ dateTimeTypes.setId(id);
+
+ //java.sql types: date/time
+ dateTimeTypes.setSqlTime(Time.valueOf(LocalTime.now()));
+ dateTimeTypes.setSqlDate(Date.valueOf(LocalDate.now()));
+ dateTimeTypes.setSqlTimestamp(Timestamp.valueOf(LocalDateTime.now()));
+
+ //java.util types: date/calendar
+ java.util.Date date = new java.util.Date();
+ dateTimeTypes.setUtilTime(date);
+ dateTimeTypes.setUtilDate(date);
+ dateTimeTypes.setUtilTimestamp(date);
+
+ //Calendar
+ Calendar calendar = Calendar.getInstance();
+ dateTimeTypes.setCalendarTime(calendar);
+ dateTimeTypes.setCalendarDate(calendar);
+ dateTimeTypes.setCalendarTimestamp(calendar);
+
+ //java.time types
+ dateTimeTypes.setLocalTime(LocalTime.now());
+ dateTimeTypes.setLocalDate(LocalDate.now());
+ dateTimeTypes.setLocalDateTime(LocalDateTime.now());
+
+ //java.time types with offset
+ dateTimeTypes.setOffsetTime(OffsetTime.now());
+ dateTimeTypes.setOffsetDateTime(OffsetDateTime.now());
+
+ EntityManager entityManager = emf.createEntityManager();
+ entityManager.getTransaction().begin();
+ entityManager.persist(dateTimeTypes);
+ entityManager.getTransaction().commit();
+ entityManager.close();
+ }
+
+ public void clean() {
+ emf.close();
+ }
+}
diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/JPA22DateTimeEntity.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/JPA22DateTimeEntity.java
new file mode 100644
index 0000000000..065385bd86
--- /dev/null
+++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/JPA22DateTimeEntity.java
@@ -0,0 +1,176 @@
+package com.baeldung.jpa.datetime;
+
+import javax.persistence.*;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.time.*;
+import java.util.Calendar;
+
+@Entity
+public class JPA22DateTimeEntity {
+
+ @Id
+ private Long id;
+
+ //java.sql types
+ private Time sqlTime;
+ private Date sqlDate;
+ private Timestamp sqlTimestamp;
+
+ //java.util types
+ @Temporal(TemporalType.TIME)
+ private java.util.Date utilTime;
+
+ @Temporal(TemporalType.DATE)
+ private java.util.Date utilDate;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private java.util.Date utilTimestamp;
+
+ //Calendar
+ @Temporal(TemporalType.TIME)
+ private Calendar calendarTime;
+
+ @Temporal(TemporalType.DATE)
+ private Calendar calendarDate;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Calendar calendarTimestamp;
+
+ // java.time types
+ @Column(name = "local_time", columnDefinition = "TIME")
+ private LocalTime localTime;
+
+ @Column(name = "local_date", columnDefinition = "DATE")
+ private LocalDate localDate;
+
+ @Column(name = "local_date_time", columnDefinition = "TIMESTAMP")
+ private LocalDateTime localDateTime;
+
+ @Column(name = "offset_time", columnDefinition = "TIME WITH TIME ZONE")
+ private OffsetTime offsetTime;
+
+ @Column(name = "offset_date_time", columnDefinition = "TIMESTAMP WITH TIME ZONE")
+ private OffsetDateTime offsetDateTime;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Time getSqlTime() {
+ return sqlTime;
+ }
+
+ public void setSqlTime(Time sqlTime) {
+ this.sqlTime = sqlTime;
+ }
+
+ public Date getSqlDate() {
+ return sqlDate;
+ }
+
+ public void setSqlDate(Date sqlDate) {
+ this.sqlDate = sqlDate;
+ }
+
+ public Timestamp getSqlTimestamp() {
+ return sqlTimestamp;
+ }
+
+ public void setSqlTimestamp(Timestamp sqlTimestamp) {
+ this.sqlTimestamp = sqlTimestamp;
+ }
+
+ public java.util.Date getUtilTime() {
+ return utilTime;
+ }
+
+ public void setUtilTime(java.util.Date utilTime) {
+ this.utilTime = utilTime;
+ }
+
+ public java.util.Date getUtilDate() {
+ return utilDate;
+ }
+
+ public void setUtilDate(java.util.Date utilDate) {
+ this.utilDate = utilDate;
+ }
+
+ public java.util.Date getUtilTimestamp() {
+ return utilTimestamp;
+ }
+
+ public void setUtilTimestamp(java.util.Date utilTimestamp) {
+ this.utilTimestamp = utilTimestamp;
+ }
+
+ public Calendar getCalendarTime() {
+ return calendarTime;
+ }
+
+ public void setCalendarTime(Calendar calendarTime) {
+ this.calendarTime = calendarTime;
+ }
+
+ public Calendar getCalendarDate() {
+ return calendarDate;
+ }
+
+ public void setCalendarDate(Calendar calendarDate) {
+ this.calendarDate = calendarDate;
+ }
+
+ public Calendar getCalendarTimestamp() {
+ return calendarTimestamp;
+ }
+
+ public void setCalendarTimestamp(Calendar calendarTimestamp) {
+ this.calendarTimestamp = calendarTimestamp;
+ }
+
+ public LocalTime getLocalTime() {
+ return localTime;
+ }
+
+ public void setLocalTime(LocalTime localTime) {
+ this.localTime = localTime;
+ }
+
+ public LocalDate getLocalDate() {
+ return localDate;
+ }
+
+ public void setLocalDate(LocalDate localDate) {
+ this.localDate = localDate;
+ }
+
+ public LocalDateTime getLocalDateTime() {
+ return localDateTime;
+ }
+
+ public void setLocalDateTime(LocalDateTime localDateTime) {
+ this.localDateTime = localDateTime;
+ }
+
+ public OffsetTime getOffsetTime() {
+ return offsetTime;
+ }
+
+ public void setOffsetTime(OffsetTime offsetTime) {
+ this.offsetTime = offsetTime;
+ }
+
+ public OffsetDateTime getOffsetDateTime() {
+ return offsetDateTime;
+ }
+
+ public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
+ this.offsetDateTime = offsetDateTime;
+ }
+}
diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/MainApp.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/MainApp.java
new file mode 100644
index 0000000000..7f23f44254
--- /dev/null
+++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/datetime/MainApp.java
@@ -0,0 +1,18 @@
+package com.baeldung.jpa.datetime;
+
+public class MainApp {
+
+ public static void main(String... args) {
+
+ DateTimeEntityRepository dateTimeEntityRepository = new DateTimeEntityRepository();
+
+ //Persist
+ dateTimeEntityRepository.save(100L);
+
+ //Find
+ JPA22DateTimeEntity dateTimeEntity = dateTimeEntityRepository.find(100L);
+
+ dateTimeEntityRepository.clean();
+ }
+
+}
\ No newline at end of file
diff --git a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml
index 433d456cc9..8592fce533 100644
--- a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml
+++ b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml
@@ -2,12 +2,14 @@
+ http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
+ version="2.2">
org.hibernate.jpa.HibernatePersistenceProvider
com.baeldung.sqlresultsetmapping.ScheduledDay
+ com.baeldung.sqlresultsetmapping.Employee
+ true
org.hibernate.jpa.HibernatePersistenceProvider
com.baeldung.jpa.stringcast.Message
+ true
@@ -39,6 +42,7 @@
org.hibernate.jpa.HibernatePersistenceProvider
com.baeldung.jpa.model.Car
+ true
@@ -66,4 +70,22 @@
+
+ org.eclipse.persistence.jpa.PersistenceProvider
+ com.baeldung.jpa.datetime.JPA22DateTimeEntity
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file