2013-07-22 50 views
1

我在Postgres有timestamp(0) without time zone列,想通過Hibernate 4.2.2將它映射到Joda-Time Instant。用於Hibernate版本4.x的Joda-Time site refersJadira UserType library。但有沒有文檔。如何使用JodaTime Instant(timestamp)與Hibernate 4.x(通過Jadira usertype)?

有人可以給我一個時間戳的例子與Hibernate 4.x使用的實體屬性,最好JPA兼容?是否有可能定義一次映射,以便我不需要使用很長的類名註釋每個時間戳屬性?

我不在乎時區。我只堅持unix時間戳到數據庫。時區由視圖層處理。

+0

[鏈接](http://java.dzone.com/articles/how-map-dates-hibernate-%E2%80%93-use DZone:如何映射日期與休眠 - 使用喬達時間) –

回答

3

托馬斯,作爲一個起點訪問此頁面的文檔中:http://jadira.sourceforge.net/usertype-userguide.html

這是那裏的例子:

@Column @Type(TYPE =「org.jadira.usertype.dateandtime.joda .PersistentLocalDateTime「) private LocalDateTime dateTime;

事實上,這幾乎是你所需要做的。

您可能需要PersistentTimestamp類(有關類的完整列表,請參閱Javadoc http://jadira.sourceforge.net/apidocs/index.html)。可用的持久化類的喬達時間:

PersistentDateMidnight
PersistentDateMidnightAsString
PersistentDateTime
PersistentDateTimeAndZone
PersistentDateTimeAndZoneWithOffset
PersistentDateTimeAsString
PersistentDateTimeWithZone
PersistentDateTimeZoneAsString
PersistentDateTimeZoneWithOffsetAsString
PersistentDurati onAsString
PersistentInstantAsMillisLong
PersistentInstantAsNanosBigInteger
PersistentInstantAsString
PersistentInstantAsTimestamp
PersistentInterval
PersistentLocalDate
PersistentLocalDateAsString
PersistentLocalDateTime
PersistentLocalDateTimeAsString
PersistentLocalTime
PersistentLocalTimeAsMillisInteger
PersistentLocalTimeAsNanosLong
PersistentLocalTimeAsString
PersistentLocalTimeAsTimestamp
PersistentMinutes
PersistentMonthDayAsString
PersistentPeriodAsString
PersistentTimeOfDay
PersistentTimeOfDayAsMillisInteger
PersistentTimeOfDayAsNanosLong
PersistentTimeOfDayAsString
PersistentTimeOfDayAsTimestamp
PersistentYearMonthAsString
PersistentYearMonthDay
PersistentYearMonthDayAsString
PersistentYears

我想你想PersistentInstantAsTimestamp,如果你不感興趣的時區,或者也許PersistentLocalDateTime。

如果有任何問題超出此範圍,您可以在此處跟進或通過http://jadira.atlassian.net/舉報,我會盡我所能提供協助。

聲明:我是Jadira Usertype的維護者。

+0

感謝你的這個罐子。我認爲這個清單在網上參考上很有趣。儘管我在幾次問題後發現它在谷歌上,但我想這個信息在主要參考中很有用。 –

相關問題