Skip to content

Commit

Permalink
HHH-11768 - Fix FK ConstraintViolationException with ordered inserts …
Browse files Browse the repository at this point in the history
…enabled and cascade persist.
  • Loading branch information
Naros committed Jun 12, 2017
1 parent e7e6cc5 commit 234849d
Showing 1 changed file with 7 additions and 3 deletions.
Expand Up @@ -1104,7 +1104,7 @@ public void sort(List<AbstractEntityInsertAction> insertions) {
//Make sure that child entries are not before parents
for ( int j = i - 1; j >= 0; j-- ) {
BatchIdentifier prevBatchIdentifier = latestBatches.get( j );
if(prevBatchIdentifier.getParentEntityNames().contains( entityName )) {
if ( prevBatchIdentifier.getParentEntityNames().contains( entityName ) ) {
latestBatches.remove( batchIdentifier );
latestBatches.add( j, batchIdentifier );
}
Expand All @@ -1114,8 +1114,12 @@ public void sort(List<AbstractEntityInsertAction> insertions) {
for ( int j = i + 1; j < latestBatches.size(); j++ ) {
BatchIdentifier nextBatchIdentifier = latestBatches.get( j );
//Take care of unidirectional @OneToOne associations but exclude bidirectional @ManyToMany
if(nextBatchIdentifier.getChildEntityNames().contains( entityName ) &&
!batchIdentifier.getChildEntityNames().contains( nextBatchIdentifier.getEntityName() )) {
if ( nextBatchIdentifier.getChildEntityNames().contains( entityName ) &&
!batchIdentifier.getChildEntityNames().contains( nextBatchIdentifier.getEntityName() ) ) {
latestBatches.remove( batchIdentifier );
latestBatches.add( j, batchIdentifier );
}
else if ( batchIdentifier.getParentEntityNames().contains( nextBatchIdentifier.getEntityName() ) ) {
latestBatches.remove( batchIdentifier );
latestBatches.add( j, batchIdentifier );
}
Expand Down

0 comments on commit 234849d

Please sign in to comment.