使用JPA2 / Hibernate持久化java.time.Instant(JDK8) [英] Persist java.time.Instant (JDK8) with JPA2/Hibernate

查看:139
本文介绍了使用JPA2 / Hibernate持久化java.time.Instant(JDK8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JPA和Hibernate都不支持JDK8中JSR-310带来的新日期/时间类(JPA ticket ,Hibernate 门票)。尽管如此,我想用JDK8日期/时间类进行编码,因为它们最终设计得很好。特别是,我对 java.time.Instant 感兴趣,并不完全支持所有 java.time。* 类型,因为我所有的实体都会使用这个特定的类(或者我现在认为,至少: - )

一种选择是编写类型转换器。然而,我们的应用程序服务器是JBoss EAP 6.3,它是JPA 2.0,但不兼容2.1,所以这是现在不存在的问题。



下一个选项是使用Hibernate用户类型(关于转换其他JSR-310类的博客文章此处)。



有更好的选择吗?感谢。

/ a>,其中提到了三种不同的JPA库:


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 the ThreeTen home page, where three different JPA libraries are mentioned:

这篇关于使用JPA2 / Hibernate持久化java.time.Instant(JDK8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆