November 13, 2016

DateTime JPA/Hibernate mapping

For mapping a Timestamp or Date in DB by hibernate we used joda time. Since, java 8 we use java.time package. But to success mapping with DateTime, LocalDate... type (joda time or java 8) we need some configurations.

1- Mapping joda time DateTime:

    With java 7 and earlier we use joda time. For mapping without any configuration we got an error. As solution, using jadira.


private DateTime _date;

2- Mapping java 8 DateTime:

    With java 8 and hibernate 5 we need just a more dependency (hibernate-java8):
    - Maven:

- Gradle:

    compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.1.1.Final'

No comments:

Post a Comment