Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Java 8 ZonedDateTime

I am using Hibernate and JPA to store my data in a database. Now I would like to save a ZonedDateTime from java.time.

The problem is, Hibernate does only ever persist the date and time. It does not care about the ZoneId or the offset.

Is there any way to persuade Hibernate to persist that information?

like image 797
Mr.H. Avatar asked Aug 14 '17 13:08

Mr.H.


1 Answers

hibernate 5 support java8 datetime types by adding hibernate-java8 dependancy but in version 5.2.10 this moved to hibernate core

(deprecated - use hibernate-core instead) Support for Java8-specific features - mainly Java8 Date/Time (JSR 310)

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-java8 -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-java8</artifactId>
</dependency>

for more information about hibernate and datetime see this

import java.time.Instant;

@Column(name = "reset_date")
private Instant resetDate = null;


setResetDate(Instant.now());

https://www.thoughts-on-java.org/hibernate-5-date-and-time/

like image 125
ali akbar azizkhani Avatar answered Oct 21 '22 12:10

ali akbar azizkhani