Can Hibernate map a Java Calendar
object to an SQL TIMESTAMP
column?
Asked
Active
Viewed 6,599 times
1 Answers
11
Yes:
@Column
@Temporal(TemporalType.TIMESTAMP)
private Calendar calendar;

Bozho
- 588,226
- 146
- 1,060
- 1,140
-
1Does this translate the date to the calendar time zone? – Derek Mahar Nov 06 '10 at 15:17
-
I'd guess the timezone is the default timezone of the virtual machine. – Bozho Nov 06 '10 at 15:19
-
Bozho, I'm afraid that link is broken. I've raised a related question at http://stackoverflow.com/questions/4117249/what-time-zone-does-hibernate-use-when-it-reads-and-writes-a-java-calendar-object – Derek Mahar Nov 07 '10 at 10:03
-
@Derek Mahar it was down for a few minutes I guess. It's up now. – Bozho Nov 07 '10 at 10:30
-
Bozho, thank you for the link to your article. It seems that the key method is `TimeZone.setDefault()`, particularly when a developer is not permitted to change `-Duser.timezone` on the JVM command line. – Derek Mahar Nov 07 '10 at 11:30
-
1Bozho, according to http://community.jboss.org/wiki/UserTypefornon-defaultTimeZone, `TimeZone.setDefault()` is not the best solution because it changes the time zone for the entire JVM (or class loader) when all that you may want is to change the time zone for a particular `Calendar` to `TIMESTAMP` mapping. – Derek Mahar Nov 07 '10 at 11:49