From 2ea0505e47559f7a1af3e0acd622595aa6d60076 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Sat, 22 Jun 2019 23:59:32 +0100 Subject: [PATCH] HHH-13453 Optimise CascadingActions for the most likely case --- .../hibernate/engine/spi/CascadingActions.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadingActions.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadingActions.java index 40979330a6..aa332bf96b 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadingActions.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadingActions.java @@ -369,21 +369,20 @@ public class CascadingActions { int propertyIndex) { if ( propertyType.isEntityType() ) { Object child = persister.getPropertyValue( parent, propertyIndex ); - String childEntityName = ((EntityType) propertyType).getAssociatedEntityName( session.getFactory() ); - if ( child != null && !isInManagedState( child, session ) - && !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient - && ForeignKeys.isTransient( childEntityName, child, null, session ) ) { - String parentEntityName = persister.getEntityName(); - String propertyName = persister.getPropertyNames()[propertyIndex]; - throw new TransientPropertyValueException( + && !(child instanceof HibernateProxy) ) { //a proxy cannot be transient and it breaks ForeignKeys.isTransient + final String childEntityName = ((EntityType) propertyType).getAssociatedEntityName(session.getFactory()); + if (ForeignKeys.isTransient(childEntityName, child, null, session)) { + String parentEntityName = persister.getEntityName(); + String propertyName = persister.getPropertyNames()[propertyIndex]; + throw new TransientPropertyValueException( "object references an unsaved transient instance - save the transient instance before flushing", childEntityName, parentEntityName, propertyName - ); - + ); + } } } }