UserType / Hibernate / JodaTime - 在哪里设置UserType全局属性? [英] UserType / Hibernate / JodaTime - where to set UserType global properties?

查看:225
本文介绍了UserType / Hibernate / JodaTime - 在哪里设置UserType全局属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用UserType 3.0.0.RC1中的 org.jadira.usertype.dateandtime.joda.PersistentDateTime 类映射JodaTime DateTime 到Hibernate。 该课程的Javadocs 提到有'databaseZone'和'jvmZone'属性,但我无法在UserType文档中找到指示如何执行此操作的任何内容。我找到了这个帖子,这似乎暗示这些是由XML类似于以下内容:

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>

我尝试将这些添加到我的hibernate配置中,但这只是给了一个错误。有谁知道这个配置需要去哪里?感谢。

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

推荐答案

这些设置确实可以放置在hibernate配置中,如下所示:

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>

原来我实际上是在参考错误的旧版UserType库,它不支持这些属性。 D'oh!

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

这篇关于UserType / Hibernate / JodaTime - 在哪里设置UserType全局属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆