HHH-3334 : Cascade-save breaks if parent ID is assigned (delays insert) and child has identity ID (early insert) (Wallace Wadge)

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20210 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Gail Badner 2010-08-20 17:18:44 +00:00
parent d3998b672e
commit 27c43633ab
2 changed files with 5 additions and 42 deletions

View File

@ -262,11 +262,6 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
boolean inTxn = source.getJDBCContext().isTransactionInProgress();
boolean shouldDelayIdentityInserts = !inTxn && !requiresImmediateIdAccess;
if ( useIdentityColumn && !shouldDelayIdentityInserts ) {
log.trace( "executing insertions" );
source.getActionQueue().executeInserts();
}
// Put a placeholder in entries, so we don't recurse back and try to save() the
// same object again. QUESTION: should this be done before onSave() is called?
// likewise, should it be done before onUpdate()?
@ -286,6 +281,11 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
cascadeBeforeSave( source, persister, entity, anything );
if ( useIdentityColumn && !shouldDelayIdentityInserts ) {
log.trace( "executing insertions" );
source.getActionQueue().executeInserts();
}
Object[] values = persister.getPropertyValuesToInsert( entity, getMergeMap( anything ), source );
Type[] types = persister.getPropertyTypes();

View File

@ -59,44 +59,7 @@ public class CascadeTestWithAssignedParentIdTest extends FunctionalTestCase {
return new FunctionalTestClassTestSuite( CascadeTestWithAssignedParentIdTest.class );
}
/**
* Saves the child object with the parent when both the one-to-many and
* many-to-one associations use cascade="all"
*/
public void testSaveChildWithParentFailureExpected() {
if ( ! IdentityGenerator.class.isAssignableFrom( getDialect().getNativeIdentifierGeneratorClass() ) ) {
reportSkip( "FailureExpected test passes when native id generator is not IdentityGenerator",
"parent insert is assigned (delayed) when child is identity (early insert)" );
fail( "test is expected to fail" );
return;
}
Session session = openSession();
Transaction txn = session.beginTransaction();
Parent parent = new Parent();
Child child = new Child();
child.setParent( parent );
parent.setChildren( Collections.singleton( child ) );
parent.setId(new Long(123L));
// this should figure out that the parent needs saving first since id is assigned.
session.save( child );
txn.commit();
session.close();
session = openSession();
txn = session.beginTransaction();
parent = ( Parent ) session.get( Parent.class, parent.getId() );
assertEquals( 1, parent.getChildren().size() );
txn.commit();
session.close();
}
public void testSaveChildWithParent() {
if ( IdentityGenerator.class.isAssignableFrom( getDialect().getNativeIdentifierGeneratorClass() ) ) {
reportSkip( "test is known to fail when native id generator is IdentityGenerator",
"parent insert is assigned (delayed) when child has identity (early insert)" );
return;
}
Session session = openSession();
Transaction txn = session.beginTransaction();
Parent parent = new Parent();