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


休眠 - 3.6.0.Final 乔达 - 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;
}

的hbm.xml

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

错误:

org.hibernate.MappingException:可以   不确定类型:   org.joda.time.contrib.hibernate.PersistentDateTime

并且没有“type =” 错误

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


12291
2018-02-21 11:26


起源



答案:


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

更新:

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

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


16
2018-02-21 11:38



哦,谢谢你提供的回复。两个jar joda-time-hibernate-1.2.jar和joda-time-1.6.2.jar所以需要添加这个也因为“org.joda.time.contrib ..”在hibernate-1.2.jar中 - Ravi Parekh
session.createQuery(“来自RateCode rr,其中rr.id.date> =:from).setDate / setTimeStamp(”from“,from)其中来自映射文件JODA.Timestamp但在.setDate中需要util.Date java.lang.NoSuchFieldError: TIMESTAMP at org.joda.time.contrib.hibernate.PersistentDateTime.nullSafeSet(PersistentDateTime.java:83) 那么如何使用setDate进行查询。谢谢 - Ravi Parekh
@ravj:更新了。 - axtavt
更新到joda-time-hibernate 1.3解决了这个问题。 - reto
更新到hibernate 1.3的+1,这是在发布此答案后发布的。 - RockMeetHardplace


答案:


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

更新:

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

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


16
2018-02-21 11:38



哦,谢谢你提供的回复。两个jar joda-time-hibernate-1.2.jar和joda-time-1.6.2.jar所以需要添加这个也因为“org.joda.time.contrib ..”在hibernate-1.2.jar中 - Ravi Parekh
session.createQuery(“来自RateCode rr,其中rr.id.date> =:from).setDate / setTimeStamp(”from“,from)其中来自映射文件JODA.Timestamp但在.setDate中需要util.Date java.lang.NoSuchFieldError: TIMESTAMP at org.joda.time.contrib.hibernate.PersistentDateTime.nullSafeSet(PersistentDateTime.java:83) 那么如何使用setDate进行查询。谢谢 - Ravi Parekh
@ravj:更新了。 - axtavt
更新到joda-time-hibernate 1.3解决了这个问题。 - reto
更新到hibernate 1.3的+1,这是在发布此答案后发布的。 - RockMeetHardplace