java pojo 中的 joda.time.DateTime 支持休眠

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5065367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:15:07  来源:igfitidea点击:

joda.time.DateTime in pojo with hibernate support

javahibernatejodatime

提问by Ravi Parekh

hibernate - 3.6.0.Final joda - 1.4 how to support direct joda.DateTime in pojo for hibernate

hibernate - 3.6.0.Final joda - 1.4 如何在 pojo 中支持直接 joda.DateTime 进行休眠

so can be session.saveOrUpdate(rateCodeId);

所以可以 session.saveOrUpdate(rateCodeId);

pojo

波乔

public class RateCodeId implements java.io.Serializable {

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

hbm.xml

hbm.xml

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

ERROR:

错误:

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

org.hibernate.MappingException:无法确定类型:org.joda.time.contrib.hibernate.PersistentDateTime

AND without "type=" ERROR

并且没有“类型=”错误

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

java.lang.ClassCastException: org.joda.time.DateTime 不能转换为 java.util.Date

回答by axtavt

Perhaps you don't have Joda-Time Hibernatein the classpath. It's needed for type="org.joda.time.contrib.hibernate.PersistentDateTime".

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

UPDATE:

更新:

It appears that Joda-time Hibernate support currently doesn't work with Hibernate 3.6, see PersistentDateTime doesn't work in hibernate 3.6 - ID: 3090209and Recompile Joda-Time Hibernate to make it work with Hibernate 3.6.

看来 Joda-time Hibernate 支持目前不适用于 Hibernate 3.6,请参阅PersistentDateTime 在 hibernate 3.6 中不起作用 - ID:3090209和重新编译 Joda-Time Hibernate 以使其与 Hibernate 3.6 一起工作

You can use User Type projectinstead (type attribute becomes type="org.jadira.usertype.dateandtime.joda.PersistentDateTime").

您可以改用用户类型项目(类型属性变为type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")。