Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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">
        <column 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

like image 806
Ravi Parekh Avatar asked Feb 21 '11 11:02

Ravi Parekh


People also ask

Is Joda datetime deprecated?

So the short answer to your question is: YES (deprecated).

Is Joda-Time format followed in Java 8?

Joda-Time is an API created by joda.org which offers better classes and having efficient methods to handle date and time than classes from java. util package like Calendar, Gregorian Calendar, Date, etc. This API is included in Java 8.0 with the java.

Does Joda datetime have time zones?

Joda-Time uses immutable objects. So rather than change the time zone ("mutate"), we instantiate a new DateTime object based on the old but with the desired difference (some other time zone).

What is Joda-Time format?

Joda-Time provides a comprehensive formatting system. There are two layers: High level - pre-packaged constant formatters. Mid level - pattern-based, like SimpleDateFormat. Low level - builder.


1 Answers

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").

like image 77
axtavt Avatar answered Oct 16 '22 19:10

axtavt