When initializing version attribute to a negative value then a TransientObjectException is thrown when loading an entity

Description

I have two entities RootEntity, and ChildEntity that are connected via a bidirectional OneToOne relationship. Both entities have a int version attribute which is initialized to -1 for newly created entities that are not yet persisted.

Persisting newly created entities root1 <-> child1, this is successful. However, when trying to load those entities in a new transaction, then I get an exception with the following stacktrace:

A corresponding reproducer test case is available here:

This reproducer test case can be successfully executed in Hibernate <= 6.6.1. In contrast, the test case fails in Hibernate 6.6.2 and 6.6.3.

Activity

Show:

Gavin King November 27, 2024 at 6:50 PM

Fixed in H7.

Gavin King November 26, 2024 at 11:39 AM

Thanks, nice catch, at first glance this looks to be a side-effect of which seems to have added a call to getEntityIdentifierIfNotUnsaved during the loading process (possibly also combined with some changes we made recently to the handling of versions in unsaved determination).

It should be very easy to fix by simply making sure that throwIfTransient() is not called during the loading process.

Fixed

Details

Assignee

Reporter

Labels

Worked in

Fix versions

Affects versions

Priority

Created November 26, 2024 at 10:50 AM
Updated February 13, 2025 at 10:17 AM
Resolved November 27, 2024 at 6:50 PM