I am update a project to spring boot 3 and hibernate 6.5.3.Final and encountered a problem when using Instant.now() in a legacy project
Previously Instant.now() had a time offset, but in the current version of hibernate it always and strictly corresponds to UTC
Using the spring.jpa.properties.hibernate.type.preferred_instant_jdbc_type=TIMESTAMP setting helped me a little, in postgres db I began to see records with the correct time offset for me +02
But when reading records, it seems not to work
I have entity:
@Data
@Entity
@SuperBuilder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
public class TestEnity {
@NonNull
private UUID id;
@NonNull
private Instant createDate;
}
Add record by EntityManager (in my timezone now 12 am):
id | create_date
----------------------------------------------------------------------
3ceca36e-710f-4ea3-223b-1118b0796c7f | 2025-04-10 12:20:30.510548
3ceca36e-710f-4ea3-223b-2228b0796c7f | 2025-04-09 12:20:30.510548
3ceca36e-710f-4ea3-223b-3338b0796c7f | 2025-04-08 12:20:30.510548
And I use querydsl for get records:
SQLQueryFactory sqlQueryFactory = new SQLQueryFactory(GenaratorQsqlUtils.createConfiguration(), dataSource);
BooleanBuilder booleanBuilder = new BooleanBuilder();
booleanBuilder.and(getDateFrom(instantFrom));
booleanBuilder.and(getDateTo(instantTo));
long count = sqlQueryFactory.select()
.from(testE)
.where(booleanBuilder) //createDate >= 2025-04-09T12:19:58Z && createDate <= 2025-04-10T12:29:58Z
.fetchCount();
And I wait I get 2 record 1118b0796c7f and 2228b0796c7f, but hibernate find only 1118b0796c7f and in debug I see:
id | create_date
----------------------------------------------------------------------
3ceca36e-710f-4ea3-223b-1118b0796c7f | 2025-04-10 10:20:30.510548
If I update record 2228b0796c7f column create_date for 2025-04-09 14:20:30.510548 (that is, in the current offset recorded in the database, I added another one +02) than I get 2 records
How it work? hibernate.type.preferred_instant_jdbc_type work only on write? How it fix for read?