0

I had an unexpected result when try to store with Hibernate (5.6.1) OffsetTime entity properties into Postgresql Time with time zone field.

For ex (if current default zone is +02):

| OffsetTime| Timez    |
| --------  | -------- |
| 00:00+01  | 00:00+02 |
| 00:00+02  | 00:00+02 |
| 00:00+03  | 00:00+02 |

Original offset was lost and stored default instead.

I researched two classes:

  • org.hibernate.type.descriptor.sql.TimeTypeDescriptor
final Time time = javaTypeDescriptor.unwrap( value, Time.class, options );
  • org.hibernate.type.descriptor.java.OffsetTimeJavaDescriptor
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
    return (X) java.sql.Time.valueOf( offsetTime.toLocalTime() );
}

I think, that I had some mistake in understanding this logic, but in another answers I saw recommendation: (LINK)

 ZoneOffset zoneOffset = ZoneOffset.systemDefault().getRules()
            .getOffset(LocalDateTime.now());
    
 Notification notification = new Notification()
   //...
 ).setClockAlarm(
      OffsetTime.of(7, 30, 0, 0, zoneOffset)
 );

So, do I must to convert all OffsetTime values to default time zone so that it store correctly?

SternK
  • 11,649
  • 22
  • 32
  • 46

0 Answers0