Merge pull request #1 from akarsh-jain/akarsh-jain-patch-1

Revert changes to isolate cyclic entity (HHH-13068) fixes
This commit is contained in:
akarsh-jain 2019-05-24 18:09:06 +05:30 committed by GitHub
commit d7a2e24aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 23 deletions

View File

@ -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 );