Skip to content

Commit 8bedd0c

Browse files
committed
Add methods to DefaultFlushEntityEventListener for Hibernate Reactive
1 parent e301b4e commit 8bedd0c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.hibernate.engine.spi.SessionFactoryImplementor;
2323
import org.hibernate.engine.spi.SessionImplementor;
2424
import org.hibernate.engine.spi.Status;
25+
import org.hibernate.event.spi.EventSource;
2526
import org.hibernate.event.spi.FlushEntityEvent;
2627
import org.hibernate.event.spi.FlushEntityEventListener;
2728
import org.hibernate.jpa.event.spi.CallbackRegistry;
@@ -75,14 +76,19 @@ public void checkId(Object object, EntityPersister persister, EntityEntry entry,
7576
if ( entryId != currentId
7677
&& !entry.getStatus().isDeletedOrGone()
7778
&& !persister.getIdentifierType().isEqual( entryId, currentId, session.getFactory() ) ) {
78-
throw new HibernateException( "Identifier of an instance of '" + persister.getEntityName()
79-
+ "' was altered from " + entryId + " to " + currentId );
79+
throwIdentifiedAlteredException( persister, entryId, currentId );
8080
}
8181
}
8282
// else this is a situation where the entity id is assigned by a post-insert
8383
// generator and was saved outside the transaction, forcing it to be delayed
8484
}
8585

86+
// Used by Hibernate Reactive
87+
protected void throwIdentifiedAlteredException(EntityPersister persister, Object entryId, Object currentId) {
88+
throw new HibernateException( "Identifier of an instance of '" + persister.getEntityName()
89+
+ "' was altered from " + entryId + " to " + currentId );
90+
}
91+
8692
private void checkNaturalId(
8793
EntityPersister persister,
8894
Object entity,
@@ -243,6 +249,13 @@ private boolean scheduleUpdate(final FlushEntityEvent event) {
243249
// we'll use scheduled updates for that.
244250
new Nullability( session, NullabilityCheckType.UPDATE ).checkNullability( values, persister );
245251

252+
addEntityUpdateActionToActionQueue( event, session, entry, values, dirtyProperties, status, persister, entity, nextVersion );
253+
254+
return intercepted;
255+
}
256+
257+
// Used by Hibernate Reactive
258+
protected void addEntityUpdateActionToActionQueue(FlushEntityEvent event, EventSource session, EntityEntry entry, Object[] values, int[] dirtyProperties, Status status, EntityPersister persister, Object entity, Object nextVersion) {
246259
// schedule the update
247260
// note that we intentionally do _not_ pass in currentPersistentState!
248261
session.getActionQueue().addAction(
@@ -262,8 +275,6 @@ private boolean scheduleUpdate(final FlushEntityEvent event) {
262275
session
263276
)
264277
);
265-
266-
return intercepted;
267278
}
268279

269280
private static int[] getDirtyProperties(FlushEntityEvent event, boolean intercepted) {

0 commit comments

Comments
 (0)