Timestamp value precision change

Hi All,

After upgrade to Spring Boot 3.1 (from 2.7.2) with hibernate version upgrade to 6.2.6, the timestamp fields return value in microseconds/nanoseconds precision (2023-09-15 01:26:20.965003) as compared to milliseconds prior to the upgrade.
Due to this now our update API calls fail with concurrent modification error as we use @Version on a Timestamp field for optimistic locking. Has anyone faced any such issues?

Is there a hibernate configuration property to enforce timestamp values to be returned in milliseconds?

Any pointers/suggestions for this will be helpful.

Thanks in advance!

Best Regards,
Ria

Hibernate simply respects the configured precision for your temporal fields. If you want to use millisecond precision, then configure it via the @Column annotation.

Thanks a lot! This helped.
Prior to the upgrade without configuring it via @Column annotation the timestamp used to be in millisecond precision. So, this is an incompatible change?

Think of it however you want. ORM 6 changed the generated schema and apparently the schema you have does not match the expectations of Hibernate ORM. If you don’t align the two, bad things will happen. If you think there is a bug or think that there is something missing in the migration guide, you are free to create a JIRA ticket for this.

I’d like to use timestamp column type (without precision). I’ve tried

@Basic
@Column(name = "TIME", precision = 0)
private ZonedDateTime time;

yet, hibernate generates the column as timestamp(6).
Is there any way to use timestamp data type without precision?
I cannot use columnDefinition as I need it to be compatible with various DBMS.

You’ll have to wait for ORM 6.5 since that comes with a new annotation @FractionalSeconds which was added as part of HHH-17575 to support 0 fractional seconds in a portable way.

1 Like