From 6e8a05f88c40131efc85cdec93c0992821cd2f0c Mon Sep 17 00:00:00 2001 From: akarsh-jain <34058090+akarsh-jain@users.noreply.github.com> Date: Fri, 24 May 2019 18:05:27 +0530 Subject: [PATCH] Revert changes to isolate cyclic entity (HHH-13068) fixes Revert changes to isolate cyclic entity (HHH-13068) fixes - so as to prevent regression spillover --- .../org/hibernate/engine/spi/ActionQueue.java | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java index 909a7efc8e..d2c1741320 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java @@ -1252,7 +1252,7 @@ public class ActionQueue { /** * Add parent and child entity names so that we know how to rearrange dependencies - * + * * @param action The action being sorted * @param batchIdentifier The batch identifier of the entity affected by the action */ @@ -1261,35 +1261,24 @@ public class ActionQueue { ClassMetadata classMetadata = action.getPersister().getClassMetadata(); if ( classMetadata != null ) { Type[] propertyTypes = classMetadata.getPropertyTypes(); - Type identifierType = classMetadata.getIdentifierType(); for ( int i = 0; i < propertyValues.length; i++ ) { Object value = propertyValues[i]; Type type = propertyTypes[i]; addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, value ); } - - if ( identifierType.isComponentType() ) { - CompositeType compositeType = (CompositeType) identifierType; - Type[] compositeIdentifierTypes = compositeType.getSubtypes(); - - for ( Type type : compositeIdentifierTypes ) { - addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, null ); - } - } + } } private void addParentChildEntityNameByPropertyAndValue(AbstractEntityInsertAction action, BatchIdentifier batchIdentifier, Type type, Object value) { - if ( type.isEntityType() ) { + if ( type.isEntityType() && value != null ) { final EntityType entityType = (EntityType) type; final String entityName = entityType.getName(); final String rootEntityName = action.getSession().getFactory().getMetamodel().entityPersister( entityName ).getRootEntityName(); if ( entityType.isOneToOne() && OneToOneType.class.cast( entityType ).getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT ) { - if ( !entityType.isReferenceToPrimaryKey() ) { - batchIdentifier.getChildEntityNames().add( entityName ); - } + batchIdentifier.getChildEntityNames().add( entityName ); if ( !rootEntityName.equals( entityName ) ) { batchIdentifier.getChildEntityNames().add( rootEntityName ); } @@ -1298,23 +1287,20 @@ public class ActionQueue { if ( !batchIdentifier.getEntityName().equals( entityName ) ) { batchIdentifier.getParentEntityNames().add( entityName ); } - if ( value != null ) { - String valueClass = value.getClass().getName(); - if ( !valueClass.equals( entityName ) ) { - batchIdentifier.getParentEntityNames().add( valueClass ); - } + String valueClass = value.getClass().getName(); + if ( !valueClass.equals( entityName ) ) { + batchIdentifier.getParentEntityNames().add( valueClass ); } if ( !rootEntityName.equals( entityName ) ) { batchIdentifier.getParentEntityNames().add( rootEntityName ); } } } - else if ( type.isCollectionType() ) { + else if ( type.isCollectionType() && value != null ) { CollectionType collectionType = (CollectionType) type; final SessionFactoryImplementor sessionFactory = ( (SessionImplementor) action.getSession() ) .getSessionFactory(); - if ( collectionType.getElementType( sessionFactory ).isEntityType() && - !sessionFactory.getMetamodel().collectionPersister( collectionType.getRole() ).isManyToMany() ) { + if ( collectionType.getElementType( sessionFactory ).isEntityType() ) { String entityName = collectionType.getAssociatedEntityName( sessionFactory ); String rootEntityName = action.getSession().getFactory().getMetamodel().entityPersister( entityName ).getRootEntityName(); batchIdentifier.getChildEntityNames().add( entityName );