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 show开发者_如何学编程s: 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 :
type="org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime"
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.
精彩评论