开发者

How can I map TIMESTAMP WITH TIME ZONE to a Java data type using Hibernate 3.3.2GA?

How can I map Oracle column types TIMESTAMP WITH TIME ZONE or TIMESTAMP WITH LOCAL TIME ZO开发者_开发百科NE to a Java data type using Hibernate 3.3.2GA? Can I map each of these to a Date or Calendar data type?


Use joda-time. It has an extension for hibernate

@Columns(columns={@Column(name="startTime"),@Column(name="startTimezone")})
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTimeTZ")
private DateTime startDateTime;

But first make sure you really need to store the time-zone. A better practice is to store times in a fixed TZ (say, UTC), and display them according to the current user preferences. People are interested in the time of an event in their timezone, and not in the timezone of the event source.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜