@Generate not working in some cases in Hibernate 6.5.3

I’m having a bit of trouble upgrading from Hibernate 6.4.10 to Hibernate 6.5.3. I have the following in an entity (Kotlin):

    @Generated(event = [EventType.INSERT, EventType.UPDATE])
    @Column(name = "version_key", columnDefinition = "VARCHAR2(1000 CHAR)", updatable = false)
    var versionKey: String? = null,

    @Generated(event = [EventType.INSERT, EventType.UPDATE], writable = true)
    @Column(name = "is_latest", updatable = false)
    var isLatest: Boolean = true,

I have a test in which I insert an object, and an Oracle database trigger sets the version_key to a string and sets is_latest to false. In Hibernate 6.4.10, when I call save() on my JpaRepository, the object that is returned from the save() method has the correct values that were set by the database trigger.

However, after updating Hibernate to 6.5.3, the versionKey is set correctly, but isLatest is set to true. In fact, even if I manually call entityManager.refresh() on the returned entity, isLatest is still set to true. In Hibernate 6.5.3, I need to call findById on my JpaRepository (immediately after calling save) to get an entity back with the correct values. Any idea if there was a change between these two versions that would impact this behavior?

Some extra details

I’m using Spring Boot 3.3.5 which includes Hibernate 6.5.3. I can verify that solely changing my Hibernate version between 6.5.3 and 6.4.10 determines whether the test described above passes or fails. I’m changing my Hibernate version with the following in my build.gradle.kts

extra["hibernate.version"] = "6.4.10.Final"

Update: I tried a few more versions of Hibernate to get some more data points on which versions do/don’t break my test. I was surprised to discover that my test works in the earlier 6.5.x versions. Here is the breakdown:

6.4.10 - PASS
6.5.0 - PASS
6.5.1 - PASS
6.5.2 - PASS
6.5.3 - FAIL
6.6.1 - FAIL

One more update: In scrolling through the issues fixed in 6.5.3, this one caught my eye: HHH-18259: Joined Inheritence with Generated wrongly resolves columns for base entity. I didn’t think to mention this before, but my entity is a base class that uses Joined Inheritance. Is it possible that the fix for HHH-18259 caused a regression?

@epernice this is probably a bug. Since Hibernate 6.5, generated values are retrieved within the mutation statement itself through JDBC APIs which allow retrieving output columns in one single statement. Previously, this happened with a subsequent select, so I’m thinking there might be some timing related issue at play, though I find it weird that one of the properties generated by the same trigger is retrieved correctly and the other one isn’t.

Maybe it’s related to the Boolan type within Oracle. Would you please try to create a simplified reproducer test case and open a new issue in our tracker? We should look into this.

Thanks - I filed HHH-18805. When I investigated more for the minimal reproduction, I discovered that the problem arises when setting a value in Oracle compound trigger AFTER STATEMENT