Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
719 views
in Technique[技术] by (71.8m points)

jpa - Persist java.time.Instant (JDK8) with JPA2/Hibernate

Neither JPA nor Hibernate currently support the new date/time classes brought by JSR-310 in JDK8 (JPA ticket, Hibernate ticket). Nonetheless, I'd like to code with the JDK8 date/time classes as they are finally well designed. In particular, I'm interested in java.time.Instant, not in full support for all java.time.* types, as all my entities will use this particular class (or so I think now, at least :-)

One option is to write a type converter, as defined by JPA 2.1. However, our app server is JBoss EAP 6.3 which is JPA 2.0 but not 2.1 compatible, so this is out of the question for now.

The next option is to use a Hibernate user type (a blog post about converting other JSR-310 classes here).

Are there better options? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Either use Hibernate 5.2.0+ or for earlier Hibernate 5 add the following dependency:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-java8</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...