具有hibernate支持的pojo中的joda.time.DateTime

Rav*_*ekh 11 java hibernate jodatime

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

所以可以 session.saveOrUpdate(rateCodeId);

POJO

public class RateCodeId implements java.io.Serializable {

    private int roomId;
    private org.joda.Time.DateTime date;
}
Run Code Online (Sandbox Code Playgroud)

的hbm.xml

 <key-property name="date" type="org.joda.time.contrib.hibernate.PersistentDateTime">
        <column length="10" name="date" />
 </key-property>
Run Code Online (Sandbox Code Playgroud)

错误:

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

并且没有"type ="ERROR

java.lang.ClassCastException:org.joda.time.DateTime无法强制转换为java.util.Date

axt*_*avt 16

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

更新:

看来Joda-time Hibernate支持目前不能与Hibernate 3.6一起使用,请参阅hibernate 3.6中不能使用PersistentDateTime - ID:3090209并重新编译Joda-Time Hibernate以使其与Hibernate 3.6一起使用.

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

  • 更新到joda-time-hibernate 1.3解决了这个问题. (4认同)