开发者

joda.time.DateTime in pojo with hibernate support

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

so can be 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">
        <colum开发者_StackOverflown length="10" name="date" />
 </key-property>

ERROR:

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

AND without "type=" ERROR

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


Perhaps you don't have Joda-Time Hibernate in the classpath. It's needed for 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: 3090209 and Recompile Joda-Time Hibernate to make it work with Hibernate 3.6.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜