2014-01-09 31 views
0

如果服務器位於印度 - 在IST中存儲時間戳值。 從美國運行服務器時 - 在EST中存儲時間戳值。我使用的是oracle數據庫和hibernate 4.0。休眠時使用jvm時區而不是我們設置的時區

請建議我如何解決這個差異。

我在下面提到的鏈接。

How can I get the current date and time in UTC or GMT in Java?

Hibernate TypeResolver

How to store date/time and timestamps in UTC time zone with JPA and Hibernate

Hibernate force timestamp to persist/load as UTC

Java, Hibernate, MySQL - store UTC date-time

回答

0

我們可以使用「-Duser.timezone = US/Eastern」屬性在任何時區啓動服務器。

-1

有類似的問題。你可以參考下面的markthegrea回答thread

+0

嗨我所有我推薦此鏈接 http://stackoverflow.com/questions/4117249/what-time-zone-does-hibernate-use-when-it-reads-and-writes-a-java-calendar -objec 但由於我使用hibernate 4,我無法看到CalendarType的上述設置方法。 請讓我知道我可以如何繼續。 –

+0

我們可以按照下面鏈接中提到的註冊類型: http://stackoverflow.com/questions/13429943/how-to-register-a-custom-type-in​​-hibernate-using-org-springframework-orm -hiberna http://java.dzone.com/articles/annotating-custom-types http://stackoverflow.com/questions/3815965/how-do-i-get-hibernate-to-呼叫我,定製的typedef –

0

因爲Hibernate的5.2,現在就可以強制可能從一個JVM通過下面的配置屬性不同的自定義時區:

<property name="hibernate.jdbc.time_zone" value="US/Eastern"/> 

有關詳細信息,請this article