From bc6708fcf6492d5705c71cfa17af18e3783fa9e2 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Thu, 31 Jan 2008 01:13:44 +0000 Subject: [PATCH] HHH-2616 : add new collection events to hibernate-configuration-3.0.dtd; added accessor for affected owner ID to AbstractCollectionEvent git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_2@14302 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../event/AbstractCollectionEvent.java | 11 +- .../hibernate/hibernate-configuration-3.0.dtd | 4 +- .../AbstractCollectionEventTest.java | 244 ++++++++++-------- .../collection/BrokenCollectionEventTest.java | 61 +++-- .../test/event/collection/Child.java | 2 - .../test/event/collection/ChildEntity.java | 3 +- .../test/event/collection/ChildValue.java | 4 - .../test/event/collection/Entity.java | 14 + .../collection/ParentWithCollection.java | 2 +- ...bstractAssociationCollectionEventTest.java | 19 +- .../ChildWithBidirectionalManyToMany.java | 4 - 11 files changed, 203 insertions(+), 165 deletions(-) create mode 100644 test/org/hibernate/test/event/collection/Entity.java diff --git a/src/org/hibernate/event/AbstractCollectionEvent.java b/src/org/hibernate/event/AbstractCollectionEvent.java index 03b9aa2111..4e4e734f0a 100644 --- a/src/org/hibernate/event/AbstractCollectionEvent.java +++ b/src/org/hibernate/event/AbstractCollectionEvent.java @@ -1,6 +1,8 @@ //$Id: $ package org.hibernate.event; +import java.io.Serializable; + import org.hibernate.collection.PersistentCollection; import org.hibernate.engine.SessionImplementor; @@ -13,11 +15,14 @@ public abstract class AbstractCollectionEvent extends AbstractEvent { private final PersistentCollection collection; private final Object affectedOwner; + private final Serializable affectedOwnerId; - public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) { + public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) { super(source); this.collection = collection; this.affectedOwner = affectedOwner; + this.affectedOwnerId = + ( ( SessionImplementor ) source ).getPersistenceContext().getEntry( affectedOwner ).getId(); } protected static Object getLoadedOwner( PersistentCollection collection, EventSource source ) { @@ -31,4 +36,8 @@ public abstract class AbstractCollectionEvent extends AbstractEvent { public Object getAffectedOwner() { return affectedOwner; } + + public Serializable getAffectedOwnerId() { + return affectedOwnerId; + } } diff --git a/src/org/hibernate/hibernate-configuration-3.0.dtd b/src/org/hibernate/hibernate-configuration-3.0.dtd index a22cd7b50e..eb7bdaefa3 100644 --- a/src/org/hibernate/hibernate-configuration-3.0.dtd +++ b/src/org/hibernate/hibernate-configuration-3.0.dtd @@ -34,10 +34,10 @@ in JNDI. - + - + diff --git a/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java b/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java index 18fd810fbb..3fed35680d 100644 --- a/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java +++ b/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java @@ -94,9 +94,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); Child child = ( Child ) parent.getChildren().iterator().next(); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionRecreateListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionRecreateListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); + checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkNumberOfResults( listeners, index ); } @@ -119,9 +119,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); - if ( newChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ ); - checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ ); + if ( newChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); + checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkNumberOfResults( listeners, index ); } @@ -143,9 +143,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); - if ( newChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ ); - checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ ); + if ( newChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); + checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkNumberOfResults( listeners, index ); } @@ -167,9 +167,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); - if ( newChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ ); - checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ ); + if ( newChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); + checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkNumberOfResults( listeners, index ); } @@ -183,8 +183,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); - if ( child instanceof ChildEntity ) { - child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() ); + if ( child instanceof Entity ) { + child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() ); } parent.addChild( child ); tx.commit(); @@ -193,16 +193,20 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } - if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ ); + ChildWithBidirectionalManyToMany childWithManyToMany = null; + if ( child instanceof ChildWithBidirectionalManyToMany ) { + childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child; + if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ ); + } } if ( !( parent.getChildren() instanceof PersistentSet ) ) { checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); } - if ( child.hasBidirectionalManyToMany() && !( getParents( child ) instanceof PersistentSet ) ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ ); + if ( childWithManyToMany != null && !( childWithManyToMany.getParents() instanceof PersistentSet ) ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), childWithManyToMany, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), childWithManyToMany, index++ ); } checkNumberOfResults( listeners, index ); } @@ -226,9 +230,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, collectionOrig, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, collectionOrig, index++ ); - if ( newChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ ); - checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ ); + if ( newChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); + checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); @@ -254,9 +258,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); - if ( newChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ ); - checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ ); + if ( newChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); + checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); @@ -272,8 +276,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); - if ( child instanceof ChildEntity ) { - child = ( ChildEntity ) s.get( child.getClass(), ( ( ChildEntity ) child).getId() ); + if ( child instanceof Entity ) { + child = ( Child ) s.get( child.getClass(), ( ( Entity ) child).getId() ); } Collection oldCollection = parent.getChildren(); parent.newChildren( createCollection() ); @@ -284,16 +288,19 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ ); } - if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child; + if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ ); + } } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); - if ( child.hasBidirectionalManyToMany() ) { + if ( child instanceof ChildWithBidirectionalManyToMany ) { // hmmm, the same parent was removed and re-added to the child's collection; // should this be considered an update? - checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ ); + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); @@ -309,8 +316,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); - if ( oldChild instanceof ChildEntity ) { - oldChild = ( ChildEntity ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild).getId() ); + if ( oldChild instanceof Entity ) { + oldChild = ( Child ) s.get( oldChild.getClass(), ( ( Entity ) oldChild).getId() ); } Collection oldCollection = parent.getChildren(); parent.newChildren( createCollection() ); @@ -321,16 +328,19 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ ); } - if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ ); + if ( oldChild instanceof ChildWithBidirectionalManyToMany ) { + ChildWithBidirectionalManyToMany oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild; + if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ ); + } } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); - if ( oldChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ ); - checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ ); - checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ ); + if ( oldChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ ); + checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); + checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); @@ -346,8 +356,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); - if ( child instanceof ChildEntity ) { - child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() ); + if ( child instanceof Entity ) { + child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() ); } parent.removeChild( child ); tx.commit(); @@ -356,14 +366,17 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } - if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child; + if ( ( ( PersistentCollection ) childWithManyToMany.getParents( ) ).wasInitialized() ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ ); + } } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkNumberOfResults( listeners, index ); } @@ -377,8 +390,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); - if ( child instanceof ChildEntity ) { - child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() ); + if ( child instanceof Entity ) { + child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() ); } parent.clearChildren(); tx.commit(); @@ -387,14 +400,17 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } - if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child; + if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ ); + } } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkNumberOfResults( listeners, index ); } @@ -415,8 +431,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { s = openSession(); tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); - if ( oldChild instanceof ChildEntity ) { - oldChild = ( Child ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild ).getId() ); + if ( oldChild instanceof Entity ) { + oldChild = ( Child ) s.get( oldChild.getClass(), ( ( Entity ) oldChild ).getId() ); } parent.removeChild( oldChild ); tx.commit(); @@ -425,14 +441,17 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } - if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ ); + if ( oldChild instanceof ChildWithBidirectionalManyToMany ) { + ChildWithBidirectionalManyToMany oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild; + if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ ); + } } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); - if ( oldChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ ); + if ( oldChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ ); } checkNumberOfResults( listeners, index ); } @@ -479,11 +498,11 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); - if ( child instanceof ChildEntity ) { - child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() ); + if ( child instanceof Entity ) { + child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() ); } parent.removeChild( child ); - if ( child instanceof ChildEntity ) { + if ( child instanceof Entity ) { s.delete( child ); } s.delete( parent ); @@ -491,14 +510,14 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { s.close(); int index = 0; checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ ); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionRemoveListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionRemoveListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionRemoveListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); + checkResult( listeners, listeners.getPostCollectionRemoveListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkNumberOfResults( listeners, index ); } @@ -513,8 +532,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() ); - if ( child instanceof ChildEntity ) { - child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() ); + if ( child instanceof Entity ) { + child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() ); } parent.removeChild( child ); otherParent.addChild( child ); @@ -524,8 +543,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ ); @@ -534,9 +553,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ ); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkNumberOfResults( listeners, index ); } @@ -551,8 +570,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() ); - if ( child instanceof ChildEntity ) { - child = ( ChildEntity ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() ); + if ( child instanceof Entity ) { + child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() ); } otherParent.addAllChildren( parent.getChildren() ); parent.clearChildren(); @@ -565,16 +584,16 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ ); } - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ ); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkNumberOfResults( listeners, index ); } @@ -598,24 +617,24 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) otherCollectionOrig ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, otherCollectionOrig, index++ ); otherChildOrig = ( Child ) otherCollectionOrig.iterator().next(); - if ( otherChildOrig.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), otherChildOrig, index++ ); + if ( otherChildOrig instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ ); } } checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherParent.getChildren(), index++ ); Child otherChild = ( Child ) otherParent.getChildren().iterator().next(); - if ( otherChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), otherChild, index++ ); + if ( otherChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, otherParent.getChildren(), index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, otherParent.getChildren(), index++ ); checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ ); - if ( otherChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChildOrig, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChildOrig, index++ ); - checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChild, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChild, index++ ); + if ( otherChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ ); + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, index++ ); @@ -649,24 +668,24 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) otherCollectionOrig ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, otherCollectionOrig, index++ ); otherChildOrig = ( Child ) otherCollectionOrig.iterator().next(); - if ( otherChildOrig.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), otherChildOrig, index++ ); + if ( otherChildOrig instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ ); } } checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherOtherParent.getChildren(), index++ ); Child otherOtherChild = ( Child ) otherOtherParent.getChildren().iterator().next(); - if ( otherOtherChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), otherOtherChild, index++ ); + if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, otherOtherParent.getChildren(), index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, otherOtherParent.getChildren(), index++ ); checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ ); - if ( otherOtherChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChildOrig, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChildOrig, index++ ); - checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherOtherChild, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherOtherChild, index++ ); + if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ ); + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ ); @@ -677,9 +696,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherOtherParent.getChildren(), index++ ); checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherOtherParent, otherOtherCollectionOrig, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherOtherParent, otherOtherCollectionOrig, index++ ); - if ( otherOtherChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherOtherChild, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherOtherChild, index++ ); + if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherOtherParent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherOtherParent, index++ ); @@ -721,11 +740,6 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { return parent; } - protected Collection getParents( Child child ) { - return ( ( child instanceof ChildWithBidirectionalManyToMany ) - ? ( ( ChildWithBidirectionalManyToMany ) child ).getParents() - : null ); - } protected void checkResult(CollectionListeners listeners, CollectionListeners.Listener listenerExpected, ParentWithCollection parent, @@ -734,14 +748,14 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { } protected void checkResult(CollectionListeners listeners, CollectionListeners.Listener listenerExpected, - Child child, + ChildWithBidirectionalManyToMany child, int index) { - checkResult( listeners, listenerExpected, child, getParents( child ), index ); + checkResult( listeners, listenerExpected, child, child.getParents(), index ); } protected void checkResult(CollectionListeners listeners, CollectionListeners.Listener listenerExpected, - Object ownerExpected, + Entity ownerExpected, Collection collExpected, int index) { assertSame( listenerExpected, listeners.getListenersCalled().get( index ) ); @@ -749,6 +763,10 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase { ownerExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner() ); + assertSame( + ownerExpected.getId(), + ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId() + ); assertSame( collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection() ); diff --git a/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java b/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java index 9606d3c6cb..44962adeff 100644 --- a/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java +++ b/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java @@ -112,7 +112,7 @@ public class BrokenCollectionEventTest extends FunctionalTestCase { /* public void testUpdateDetachedParentOneChildToNullFailureExpected() { CollectionListeners listeners = new CollectionListeners( getSessions() ); - AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" ); + ParentWithCollection parent = createParentWithOneChild( "parent", "child" ); Child oldChild = ( Child ) parent.getChildren().iterator().next(); assertEquals( 1, parent.getChildren().size() ); listeners.clear(); @@ -126,9 +126,9 @@ public class BrokenCollectionEventTest extends FunctionalTestCase { int index = 0; checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); - if ( oldChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ ); + if ( oldChild instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ ); } // pre- and post- collection recreate events should be created when updating an entity with a "null" collection checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); @@ -186,7 +186,7 @@ public class BrokenCollectionEventTest extends FunctionalTestCase { /* public void testUpdateParentOneChildToNullFailureExpected() { CollectionListeners listeners = new CollectionListeners( getSessions() ); - AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" ); + ParentWithCollection parent = createParentWithOneChild( "parent", "child" ); Child oldChild = ( Child ) parent.getChildren().iterator().next(); assertEquals( 1, parent.getChildren().size() ); listeners.clear(); @@ -204,14 +204,18 @@ public class BrokenCollectionEventTest extends FunctionalTestCase { if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ ); } - if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ ); + ChildWithBidirectionalManyToMany oldChildWithManyToMany = null; + if ( oldChild instanceof ChildWithBidirectionalManyToMany ) { + oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild; + if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ ); + } } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); - if ( oldChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ ); + if ( oldChildWithManyToMany != null ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChildWithManyToMany, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChildWithManyToMany, index++ ); } // pre- and post- collection recreate events should be created when updating an entity with a "null" collection checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); @@ -221,7 +225,7 @@ public class BrokenCollectionEventTest extends FunctionalTestCase { public void testUpdateMergedParentOneChildToNullFailureExpected() { CollectionListeners listeners = new CollectionListeners( getSessions() ); - AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" ); + ParentWithCollection parent = createParentWithOneChild( "parent", "child" ); assertEquals( 1, parent.getChildren().size() ); listeners.clear(); Session s = openSession(); @@ -233,14 +237,18 @@ public class BrokenCollectionEventTest extends FunctionalTestCase { s.close(); int index = 0; Child oldChild = ( Child ) oldCollection.iterator().next(); - if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ ); + ChildWithBidirectionalManyToMany oldChildWithManyToMany = null; + if ( oldChild instanceof ChildWithBidirectionalManyToMany ) { + oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild; + if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) { + } + checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); - if ( oldChild.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ ); + if ( oldChildWithManyToMany != null ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChildWithManyToMany, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChildWithManyToMany, index++ ); } // pre- and post- collection recreate events should be created when updating an entity with a "null" collection checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); @@ -282,27 +290,22 @@ public class BrokenCollectionEventTest extends FunctionalTestCase { return parent; } - private Collection getParents( Child child ) { - return ( ( child instanceof ChildWithBidirectionalManyToMany ) - ? ( ( ChildWithBidirectionalManyToMany ) child ).getParents() - : null ); - } - private void checkResult(CollectionListeners listeners, + protected void checkResult(CollectionListeners listeners, CollectionListeners.Listener listenerExpected, ParentWithCollection parent, int index) { checkResult( listeners, listenerExpected, parent, parent.getChildren(), index ); } - private void checkResult(CollectionListeners listeners, + protected void checkResult(CollectionListeners listeners, CollectionListeners.Listener listenerExpected, - Child child, + ChildWithBidirectionalManyToMany child, int index) { - checkResult( listeners, listenerExpected, child, getParents( child ), index ); + checkResult( listeners, listenerExpected, child, child.getParents(), index ); } - private void checkResult(CollectionListeners listeners, + protected void checkResult(CollectionListeners listeners, CollectionListeners.Listener listenerExpected, - Object ownerExpected, + Entity ownerExpected, Collection collExpected, int index) { assertSame( listenerExpected, listeners.getListenersCalled().get( index ) ); @@ -310,6 +313,10 @@ public class BrokenCollectionEventTest extends FunctionalTestCase { ownerExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner() ); + assertSame( + ownerExpected.getId(), + ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId() + ); assertSame( collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection() ); diff --git a/test/org/hibernate/test/event/collection/Child.java b/test/org/hibernate/test/event/collection/Child.java index 42323f0cef..90c7b77dda 100644 --- a/test/org/hibernate/test/event/collection/Child.java +++ b/test/org/hibernate/test/event/collection/Child.java @@ -27,8 +27,6 @@ package org.hibernate.test.event.collection; */ public interface Child { - boolean hasBidirectionalManyToMany(); - String getName(); void setName(String name); diff --git a/test/org/hibernate/test/event/collection/ChildEntity.java b/test/org/hibernate/test/event/collection/ChildEntity.java index 4b622ac3be..3f9f02aa8a 100644 --- a/test/org/hibernate/test/event/collection/ChildEntity.java +++ b/test/org/hibernate/test/event/collection/ChildEntity.java @@ -25,10 +25,9 @@ package org.hibernate.test.event.collection; * * @author Gail Badner */ -public class ChildEntity extends ChildValue { +public class ChildEntity extends ChildValue implements Entity { private Long id; - public ChildEntity() { super(); } diff --git a/test/org/hibernate/test/event/collection/ChildValue.java b/test/org/hibernate/test/event/collection/ChildValue.java index 4c9e8bebc6..773cc4a7ba 100644 --- a/test/org/hibernate/test/event/collection/ChildValue.java +++ b/test/org/hibernate/test/event/collection/ChildValue.java @@ -35,10 +35,6 @@ public class ChildValue implements Child { this.name = name; } - public boolean hasBidirectionalManyToMany() { - return false; - } - public String getName() { return name; } diff --git a/test/org/hibernate/test/event/collection/Entity.java b/test/org/hibernate/test/event/collection/Entity.java new file mode 100644 index 0000000000..2a8b645c10 --- /dev/null +++ b/test/org/hibernate/test/event/collection/Entity.java @@ -0,0 +1,14 @@ +package org.hibernate.test.event.collection; + +/** + * Created by IntelliJ IDEA. + * User: gbadner + * Date: Jan 30, 2008 + * Time: 2:39:37 PM + * To change this template use File | Settings | File Templates. + */ +public interface Entity { + Long getId(); + + void setId(Long id); +} diff --git a/test/org/hibernate/test/event/collection/ParentWithCollection.java b/test/org/hibernate/test/event/collection/ParentWithCollection.java index 2ee6e45c8d..d98be9f36f 100644 --- a/test/org/hibernate/test/event/collection/ParentWithCollection.java +++ b/test/org/hibernate/test/event/collection/ParentWithCollection.java @@ -27,7 +27,7 @@ import java.util.Collection; * * @author Gail Badner */ -public interface ParentWithCollection { +public interface ParentWithCollection extends Entity { void newChildren(Collection collection); Child createChild(String name); diff --git a/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java b/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java index ee9adc5037..4077e922e2 100644 --- a/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java +++ b/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java @@ -21,12 +21,13 @@ */ package org.hibernate.test.event.collection.association; -import org.hibernate.test.event.collection.AbstractCollectionEventTest; -import org.hibernate.test.event.collection.CollectionListeners; -import org.hibernate.test.event.collection.ChildEntity; -import org.hibernate.test.event.collection.ParentWithCollection; import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.test.event.collection.AbstractCollectionEventTest; +import org.hibernate.test.event.collection.ChildEntity; +import org.hibernate.test.event.collection.CollectionListeners; +import org.hibernate.test.event.collection.ParentWithCollection; +import org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToMany; /** * @@ -52,14 +53,14 @@ public abstract class AbstractAssociationCollectionEventTest extends AbstractCol s.close(); int index = 0; checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ ); - if ( child.hasBidirectionalManyToMany() ) { - checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ ); - checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ ); + if ( child instanceof ChildWithBidirectionalManyToMany ) { + checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); + checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkNumberOfResults( listeners, index ); } diff --git a/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java b/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java index 771841e6f6..bf93e34623 100644 --- a/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java +++ b/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java @@ -40,10 +40,6 @@ public class ChildWithBidirectionalManyToMany extends ChildEntity { this.parents = parents; } - public boolean hasBidirectionalManyToMany() { - return true; - } - public Collection getParents() { return parents; }