javahibernatemavenjodatimeusertype

Which Jars I'm confused... Usertype, hibernate 4, JodaTime


I have identified that I need to use

<mapping class="org.jadira.usertype.dateandtime.joda.PersistentLocalDate" />
<mapping class="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime" />

classes for persisting in the database. I am really confused regarding which jars to download for these two classes I want to persist.

Should I use joda time classes and usertype classes to persist, what is the relation between them. I am using hibernate 4.

I also see that there is 3.2.0GA and 3.2.0CR11 what does this mean. In the maven repository for many of the packages it is written adds hibernate support! but which version?
I am trying to solve this from 3 days now...


Solution

  • The Joda Time User Type classes are not meant for mappings. You map entities, not UserTypes.

    Hibernate defines the following data structures:

    1. An Entity is the Object equivalent of a database row. It has an @Id that maps to the associated row's primary key.

    2. An Embeddable is an Object that maps to one or more columns except for the primary key. It's always depended on the parent Entity.

    3. Both Entity and Embeddable may contain non-primary key column mappings, and the Java-to-SQL type bridge is being handled by Hibernate Types.

    4. You can define your own User Types to represent other structures such as Money or Currency.

    So, the Jadira types are bridging the Joda DateTime Object types to DATE, TIME, and TIMESTAMP SQL types. If you don't need to use Joda, you'd have to rely on java.util.Date, java.util.Calendar or java.sql.Date for your Entity property types.