When i learn about java 8, I have thinking about how to use Java Date and Time in POJOs. i have tried using converters,but i’d don’t satisfied using it. Timeline in twitter gave me information, Hibernate ORM 5.0.0 release. I Reading the spesification And…

Java 8 support

Well, ok.. not all of Java 8. Specifically we have added support for Java 8 Date and Time API in regards to easily mapping attributes in your domain model using the Java 8 Date and Time API types to the database. This support is available under the dedicated hibernate-java8 artifact (to isolate Java 8 dependencies). For additional information, see the Basic Types chapter in the Domain Model Mapping Guide.

Gotcha…!!, Let’s Go to Code!!!

I’m Create Sample Table To test the Code
Point  Test is Database type and Java8 Object

  • TimeStamp = LocalDateTime
  • Time = LocalTime
  • Date = LocalDate

 
pom.xml

Hibernate 5 support LocalDateTime available under the dedicated hibernate-java8 artifact.

POJO’s

Method Getter’s and Setter’s automatically generated by annotation @Data using library Projectlombok.

Main Class

The Main Class create 10 of data and persist in Database.

Results
Result

For All Code you can see in my Github.

Requirement Testing,

  • Maria DB 10
  • Java 1.8
  • Hibernate 5.0.0.Final

Reference