Persist Joda-time's DateTime via Hibernate

后端 未结 4 1270
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 18:33

I\'m using Jodatime in my Play app, but currently having to do a bunch of converting back and forth from/to java.util.Date and java.sql.Time.

4条回答
  •  旧巷少年郎
    2020-12-13 18:48

    For Hibernate 3 add the following annotation to your date field:

    @Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
    

    Hibernate will now do the dirty work for you.

    (Make sure you have joda-time-hibernate.jar in your classpath)

    UPDATE:

    For Hibernate 4 and 5 add the following annotation:

    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    

    (Make sure you have jadira-usertype-core.jar in your classpath)

提交回复
热议问题