Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UserType / Hibernate / JodaTime - where to set UserType global properties?

I'm using the org.jadira.usertype.dateandtime.joda.PersistentDateTime class from UserType 3.0.0.RC1 to map a JodaTime DateTime to Hibernate. The Javadocs for the class mention that there are 'databaseZone' and 'jvmZone' properties which I would like to set, but I cannot find anything in the UserType documentation that indicates how to do this. I found this thread which seems to imply that these are set by XML similar to the following:

<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
<prop key="jadira.usertype.databaseZone">jvm</prop>

I tried adding these to my hibernate configuration, but that just gave an error. Does anyone know where this configuration needs to go? Thanks.

like image 469
Robert Johnson Avatar asked May 10 '12 21:05

Robert Johnson


1 Answers

Those settings can indeed be placed in the hibernate configuration, as like the following:

<session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/SOME_DATABASE</property>
    <property name="connection.username">root</property>
    <property name="connection.password">password</property>

    ...

    <property name="jadira.usertype.databaseZone">UTC</property>
    <property name="jadira.usertype.javaZone">UTC</property>

</session-factory>

Turns out I was actually referencing an old version of the UserType library by mistake, which didn't support those properties. D'oh!

like image 121
Robert Johnson Avatar answered Oct 27 '22 04:10

Robert Johnson