79566387

Date: 2025-04-10 10:35:07
Score: 1.5
Natty:
Report link

You're migrating a legacy project to Spring Boot 3 and Hibernate 6.5.3, and noticed that timestamps written using Instant.now() now behave differently — they are stored with a +02 offset when using spring.jpa.properties.hibernate.type.preferred_instant_jdbc_type=TIMESTAMP, but when reading them back, Hibernate treats them as UTC, leading to incorrect comparisons in queries. This happens because the setting only affects how Hibernate writes Instant values, not how it reads them. Since PostgreSQL stores TIMESTAMP WITHOUT TIME ZONE without timezone context, Hibernate assumes it's UTC during reads, even if the actual value was saved in local time. To fix this, it's recommended to either switch the column type to TIMESTAMP WITH TIME ZONE, which handles conversions properly, or store all times in UTC and convert to the desired timezone at the presentation layer.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Single line (0.5):
  • Low reputation (1):
Posted by: Makarand Hinge