1

我将 Joda 库用于我的 Date/Time 对象,并使用 jadira userType 项目通过 Hibernate 在我的 MySQL 数据库中保存这些东西。

运行应用程序时,我得到

4 mars 2013 18:48:18 org.jadira.usertype.spi.reflectionutils.JavaTimeZoneWorkaroundHelper <clinit>
ATTENTION: Under JDK 6 it may not be possible to handle DST transitions correctly
4 mars 2013 18:48:18 org.jadira.usertype.spi.reflectionutils.JavaTimeZoneWorkaroundHelper <clinit>
GRAVE: Running under a Zone that uses daylight saving time. To avoid incorrect datetimes being stored during DST transition, either update to JDK 7 or use a Timezone for the JDK without Daylight Saving Time

所以从文本中我有两个选择: - 安装 JDK 7,我不想这样做(我在 mac OS 10.6.8 上,我也不想使用“太新”的 java 版本) -使用没有 DST 的时区。这意味着我必须将我的 JVM 的默认 TimeZone 设置为俄罗斯或南美洲的某个地方。

  • 我可以简单地禁用JavaTimeZoneWorkaroundHelperJadira 的功能吗?如何 ?

  • 我想到了另一种选择:不要将 jadira 用于它提供的功能(将 joda 对象转换为字符串以及从字符串转换为 joda 对象)并自己进行转换器。

你有什么建议?谢谢

4

3 回答 3

0

You can explicitly set java and database time zones used for mapping independent of the machine your app is running. Generally it is good practice to store date and time in UTC time zone in database. Try if this solves your problem.

 @TypeDef(name = "myDateTime", 
          typeClass = org.jadira.usertype.dateandtime.joda.PersistentDateTime.class,
      parameters = {@Parameter(value="UTC", name="databaseZone"), 
                    @Parameter(value="UTC", name="javaZone")})
于 2013-03-04T18:38:51.457 回答
0

如果将此 @TypeDef 添加到 package-info.java 文件中,并将 @Type(name = "myDateTime") 添加到应该具有此类型的属性中,它会完美运行。

于 2013-06-20T09:12:26.757 回答
0

由于创建了此问题,因此创建了删除消息的用户类型库的更新版本。因此,如果您在 maven central 中使用 3.2.0.GA等最新版本。它解决了这个问题。

于 2015-05-13T08:41:45.410 回答