So I've added your class to my project as a custom user type and used the custom type on the attribute. I've set mySQL global and session timezones to GMT, but when I persist the object to the database the timezone is still being converted even when the calendar's timezone is set to GMT. If I don't set the timezone, it persists as I would expect.
It seems the gmt timezone is ignored when persisting. But from the code snippets provided, I cannot tell why. Pls provide more information: Did you use the user type as is? Please provide the code of the entity declaration and how you persist the entity.
For me even saving a calendar object does not take the time zone into consideration. Doesn't matter what time zone the calendar object has, it always gets saved using the system/database time zone.
I believe there's a typo in your final solution:
ReplyDelete@Override
public Class returnedClass() {
return ZuluCalendar.class;
}
no mention of ZuluCalendar.class appears in anything previous.
Yes, thanks. I corrected it.
ReplyDeleteSo I've added your class to my project as a custom user type and used the custom type on the attribute. I've set mySQL global and session timezones to GMT, but when I persist the object to the database the timezone is still being converted even when the calendar's timezone is set to GMT. If I don't set the timezone, it persists as I would expect.
ReplyDeleteCalendar calGMT = Calendar.getInstance();
calGMT.setTimeZone(TimeZone.getTimeZone("GMT"));
calGMT.set(1951, 1, 15, 0,00,00);
I would expect that when this is persisted that the value in the row in mysql would be:
'1951-02-15 00:00:01'
instead it is:
'1951-02-14 18:00:01'
If I don't set the calendar's timezone then I get the expected value of: '1951-02-15 00:00:01'
My system timezone is CST.
Know what is happening?
It seems the gmt timezone is ignored when persisting. But from the code snippets provided, I cannot tell why. Pls provide more information: Did you use the user type as is? Please provide the code of the entity declaration and how you persist the entity.
ReplyDeleteFor me even saving a calendar object does not take the time zone into consideration. Doesn't matter what time zone the calendar object has, it always gets saved using the system/database time zone.
ReplyDeleteThis implementation appears to now be out of date with version 4.x of Hibernate (e.g. nullSafeSet impl must use SessionImplementor, etc).
ReplyDelete