java - pojo 中的 joda.time.DateTime 支持 hibernate

标签 java hibernate jodatime

hibernate - 3.6.0.Final 乔达 - 1.4 如何在 pojo 中支持直接 joda.DateTime for hibernate

也可以是 session.saveOrUpdate(rateCodeId);

波乔

public class RateCodeId implements java.io.Serializable {

    private int roomId;
    private org.joda.Time.DateTime date;
}

hbm.xml

 <key-property name="date" type="org.joda.time.contrib.hibernate.PersistentDateTime">
        <column length="10" name="date" />
 </key-property>

错误:

org.hibernate.MappingException: Could not determine type for: org.joda.time.contrib.hibernate.PersistentDateTime

AND 没有 "type=" 错误

java.lang.ClassCastException: org.joda.time.DateTime cannot be cast to java.util.Date

最佳答案

也许你没有Joda-Time Hibernate在类路径中。 type="org.joda.time.contrib.hibernate.PersistentDateTime" 需要它。

更新:

看来 Joda-time Hibernate 支持目前不适用于 Hibernate 3.6,请参阅 PersistentDateTime doesn't work in hibernate 3.6 - ID: 3090209Recompile Joda-Time Hibernate to make it work with Hibernate 3.6 .

您可以使用 User Type project相反(类型属性变为 type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")。

关于java - pojo 中的 joda.time.DateTime 支持 hibernate ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5065367/

相关文章:

java - 无法在 Person 和 Address 类之间建立 'many-to-many' 关系

Java API 获得一年的夏令时界限

java - Exe4J 返回异常“?

java - 如何使用 java 从 hdfs 读取多个文件?

java - 从 AlertDialog 中创建并显示 Toasts/Snackbars

java - Hibernate、JPA、JDBC 还是?

java - 回复 : Youtube rating

java - Eclipse 调试器显示 Hibernate 管理的对象尚未延迟初始化

java - 在 Joda-Time 中,将 DateTime 设置为月初

scala - 在Scala中将自纪元以来的秒数转换为joda DateTime