About the HB-1006 - Calendar loses time zone information fix :
Oracle, MySQL, SQLServer and many other databases don't have any time zone information associated to their timestamp column types. Worst than that, those three databases don't serialize the timestamp in a timezone-neutral format ( a long representing milliseconds since a given point in time. For example : 1100700270875 ), but as a "String" representation of it in a given time zone ( For example : 2004-11-17 10:00:00 ).
Since a java.sql.Timestamp only represents a time in millis without any time zone information, and the database takes a String representation in a specific time zone, JDBC provides two methods in the PreparedStatement interface to set timestamp value. The first one only takes the java.sql.Timestamp, and will use the default JVM time zone. The second one takes a java.sql.Timestamp AND a java.util.Calendar, that the statement will use to fetch the time zone. So, for example, if your JVM runs in GMT and you want to set a Calendar that is set to 2004-11-17 10:00:00 EST, if you use the first method, '2004-11-17 15:00:00' will be set, and '2004-11-17 10:00:00' will be set for the second method.
To match those two methods, equivalent methods were published in the ResultSet : getTimestamp( java.sql.Timestamp ) and getTimestamp( java.sql.Timestamp, java.util.Calendar ).
Fix #HB-1006 proposed to use the second method of the PreparedStatement interface to serialize timestamps to the database. Although this fix works for databases that supports "timestamp with time zone" column types, where values put in the database will be '2004-11-17 10:00:00 EST' and '2004-11-17 15:00:00 GMT', for most of the databases, the timestamp saved doesn't contain any time zone information ( '2004-11-17 10:00:00' and '2004-11-17 15:00:00' ), so the value doesn't have any meaning except if we know the time zone used to serialize it, and use the second ResultSet method to get back the value.
Hibernate's CalendarType class, since it needs to be as generic as possible, can't use the second ResultSet method to get the value back from the database. At this point, Hibernate doesn't have any idea in what time zone the value was stored. A user type could be written to serialize and read the values in a hard-coded, different time zone than the default JVM time zone. A user type could also be written to store the timestamp AND the timezone, and this would allow to get the timestamp in the right format. But the default type can't adjust to those features, so i think has to use the first PreparedStatement method, the one that doesn't receive a Calendar and uses the default JVM time zone to serialize the value to the database. I think this fix should be reverted.
What do you think about that ? Is there something I don't understand ?
Thank you !
|