Take the 2-minute tour ×

i have a persistent entity with a LocalTime field mapped to a time without time zone column in a postgre table, i populate this field in my application like this:

int hour = 10
int minutes = 12
MyEntity e = new MyEntity()
e.setTime(new LocalTime(hour, minutes) );

then i persist the entity on the db using hibernate, later in the application i retrieve the entity and display the time field, it correctly shows 10:12 but when i see the value on the table (using pg-admin), it shows: 04:12 when it should be 10:12, the timezone in my jvm and in my sistem is CST (wich is UTC-6) it looks to me that somewhere in either hibernate or jodatime my time field is begin converted to my timezone both when inserting to the db and when retrieving the values, im i correct? is there any way of preventing this behaivor?, im using jre 1.6.0_22,hibernate 3, joda-time 1.5.1 and joda-time-hibernate 1.2

edit: forgot to mention that the field is mapped in hibernate with :

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Well, it may be out of date, but the docs for a class called PersistentLocalTime say this:

Persist LocalTime via Hibernate as a SQL TIME datatype - note that sub-second values will not be retained. This type is basically compatible with org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime. However, note that org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime contains a bug where times written down will be offset from GMT due to its use of Time.setTime(long). This class is not affected by this issue, but this means you cannot rely on the interpretation of this type to be the same for both classes.

(Emphasis mine.)

Sounds like you're running into that problem, but that using PersistentLocalTime instead would fix it.

share|improve this answer
yay, jon skeet to the rescue =), just to mention that this class in the usertype for hibernate project: usertype.sourceforge.net, using org.jadira.usertype.dateandtime.joda.PersistentLocalTime as type in the mapping file effectively solves this issue. –  Harima555 Dec 11 '10 at 22:05

Your Answer


