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

徘徊边缘 提交于 2019-12-06 02:47:41

问题


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.


回答1:


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!




回答2:


Those settings need to go into your persistence.xml.

An example is shown here



来源:https://stackoverflow.com/questions/10542507/usertype-hibernate-jodatime-where-to-set-usertype-global-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!