HHH-18032 CompositeId, when the id assigned by PrePersist method an HibernateException: identifier of an instance of _ was altered is thrown

This commit is contained in:
Andrea Boriero 2024-05-02 13:24:55 +02:00 committed by Andrea Boriero
parent 480e09fc4c
commit 9d54924c79
1 changed files with 3 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.EventSource;
import org.hibernate.id.Assigned;
import org.hibernate.id.CompositeNestedGeneratedValueGenerator;
import org.hibernate.id.IdentifierGenerationException;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
@ -199,7 +200,8 @@ public abstract class AbstractSaveEventListener<C>
processIfSelfDirtinessTracker( entity, SelfDirtinessTracker::$$_hibernate_clearDirtyAttributes );
processIfManagedEntity( entity, (managedEntity) -> managedEntity.$$_hibernate_setUseTracker( true ) );
if ( persister.getGenerator() instanceof Assigned ) {
final Generator generator = persister.getGenerator();
if ( generator instanceof Assigned || generator instanceof CompositeNestedGeneratedValueGenerator ) {
id = persister.getIdentifier( entity, source );
if ( id == null ) {
throw new IdentifierGenerationException(