6

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.

Robert Johnson
  • 632
  • 6
  • 25

2 Answers2

4

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!

Robert Johnson
  • 632
  • 6
  • 25
0

Those settings need to go into your persistence.xml.

An example is shown here

Community
  • 1
  • 1
Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
  • Thanks, but unfortunately I don't have a persistence.xml file; in the project I am working on we have got all of these properties configured in the 'session-factory' bean managed by Spring. Nice to know the alternative is there though. – Robert Johnson Nov 20 '12 at 11:25