Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 19:00:53 -0500 (Tue, 07 Nov 2006)
New Revision: 10759
Added:
trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
trunk/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java
trunk/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java
Modified:
trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
trunk/Hibernate3/test/org/hibernate/test/ops/CreateTest.java
trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
trunk/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/ops/Node.java
trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
Log:
hhh-1564 : delete + versioned + collections = extra updates
Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
===================================================================
---
trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-11-07
23:50:28 UTC (rev 10758)
+++
trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-11-08
00:00:53 UTC (rev 10759)
@@ -52,7 +52,7 @@
public void onDelete(DeleteEvent event, Set transientEntities) throws HibernateException
{
final EventSource source = event.getSession();
-
+
final PersistenceContext persistenceContext = source.getPersistenceContext();
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
@@ -82,13 +82,13 @@
"the detached instance passed to delete() had a null identifier"
);
}
-
+
EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
persistenceContext.checkUniqueness(key, entity);
new OnUpdateVisitor( source, id ).process( entity, persister );
-
+
version = persister.getVersion( entity, source.getEntityMode() );
entityEntry = persistenceContext.addEntity(
@@ -147,8 +147,10 @@
*
* @param session The session which is the source of the event
* @param entity The entity being delete processed
- * @param cascadeDeleteEnabled
+ * @param cascadeDeleteEnabled Is cascading of deletes enabled
* @param persister The entity persister
+ * @param transientEntities A cache of already visited transient entities
+ * (to avoid infinite recursion).
*/
protected void deleteTransientEntity(
EventSource session,
@@ -182,9 +184,7 @@
}
final PersistenceContext persistenceContext = session.getPersistenceContext();
-
- Type[] propTypes = persister.getPropertyTypes();
-
+ final Type[] propTypes = persister.getPropertyTypes();
final Object version = entityEntry.getVersion();
final Object[] currentState;
@@ -195,14 +195,7 @@
currentState = entityEntry.getLoadedState();
}
- final Object[] deletedState = new Object[propTypes.length];
- TypeFactory.deepCopy(
- currentState,
- propTypes,
- persister.getPropertyUpdateability(),
- deletedState,
- session
- );
+ final Object[] deletedState = createDeletedState( persister, currentState, session );
entityEntry.setDeletedState(deletedState);
session.getInterceptor().onDelete(
@@ -211,7 +204,7 @@
deletedState,
persister.getPropertyNames(),
propTypes
- );
+ );
// before any callbacks, etc, so subdeletions see that this deletion happened first
persistenceContext.setEntryStatus(entityEntry, Status.DELETED);
@@ -220,7 +213,7 @@
cascadeBeforeDelete( session, persister, entity, entityEntry, transientEntities );
new ForeignKeys.Nullifier(entity, true, false, session)
- .nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
+ .nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
new Nullability(session).checkNullability( entityEntry.getDeletedState(), persister,
true );
persistenceContext.getNullifiableEntityKeys().add(key);
@@ -234,8 +227,8 @@
persister,
isCascadeDeleteEnabled,
session
- )
- );
+ )
+ );
cascadeAfterDelete( session, persister, entity, transientEntities );
@@ -243,7 +236,16 @@
// override the stale snapshot
// This is now handled by removeEntity() in EntityDeleteAction
//persistenceContext.removeDatabaseSnapshot(key);
+ }
+ private Object[] createDeletedState(EntityPersister persister, Object[] currentState,
EventSource session) {
+ Type[] propTypes = persister.getPropertyTypes();
+ final Object[] deletedState = new Object[propTypes.length];
+// TypeFactory.deepCopy( currentState, propTypes, persister.getPropertyUpdateability(),
deletedState, session );
+ boolean[] copyability = new boolean[propTypes.length];
+ java.util.Arrays.fill( copyability, true );
+ TypeFactory.deepCopy( currentState, propTypes, copyability, deletedState, session );
+ return deletedState;
}
protected boolean invokeDeleteLifecycle(EventSource session, Object entity,
EntityPersister persister) {
@@ -256,7 +258,7 @@
}
return false;
}
-
+
protected void cascadeBeforeDelete(
EventSource session,
EntityPersister persister,
Added: trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2006-11-07
23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2006-11-08
00:00:53 UTC (rev 10759)
@@ -0,0 +1,51 @@
+package org.hibernate.test.ops;
+
+import java.util.Iterator;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractOperationTestCase extends TestCase {
+ public AbstractOperationTestCase(String name) {
+ super( name );
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true");
+ cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml",
"ops/OptLockEntity.hbm.xml" };
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return null;
+ }
+
+ protected void clearCounts() {
+ getSessions().getStatistics().clear();
+ }
+
+ protected void assertInsertCount(int expected) {
+ int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
+ assertEquals( "unexpected insert count", expected, inserts );
+ }
+
+ protected void assertUpdateCount(int expected) {
+ int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
+ assertEquals( "unexpected update counts", expected, updates );
+ }
+
+ protected void assertDeleteCount(int expected) {
+ int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
+ assertEquals( "unexpected delete counts", expected, deletes );
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/CreateTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/CreateTest.java 2006-11-07 23:50:28 UTC
(rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/CreateTest.java 2006-11-08 00:00:53 UTC
(rev 10759)
@@ -10,24 +10,52 @@
import org.hibernate.PersistentObjectException;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.exception.ConstraintViolationException;
-import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
-public class CreateTest extends TestCase {
-
+public class CreateTest extends AbstractOperationTestCase {
+
public CreateTest(String str) {
- super(str);
+ super( str );
}
-
+
+ public static Test suite() {
+ return new TestSuite( CreateTest.class );
+ }
+
+ public void testNoUpdatesOnCreateVersionedWithCollection() {
+ clearCounts();
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ VersionedEntity root = new VersionedEntity( "root", "root" );
+ VersionedEntity child = new VersionedEntity( "c1", "child-1" );
+ root.getChildren().add( child );
+ child.setParent( root );
+ s.save(root);
+ tx.commit();
+ s.close();
+
+ assertInsertCount( 2 );
+ assertUpdateCount( 0 );
+ assertDeleteCount( 0 );
+
+ s = openSession();
+ tx = s.beginTransaction();
+ s.delete( root );
+ tx.commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertDeleteCount( 2 );
+ }
+
public void testCreateTree() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
Node root = new Node("root");
@@ -36,7 +64,7 @@
s.persist(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
assertUpdateCount(0);
@@ -49,15 +77,15 @@
System.out.println("committing");
tx.commit();
s.close();
-
+
assertInsertCount(3);
assertUpdateCount(0);
}
-
+
public void testCreateTreeWithGeneratedId() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
NumberedNode root = new NumberedNode("root");
@@ -66,7 +94,7 @@
s.persist(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
assertUpdateCount(0);
@@ -77,11 +105,11 @@
root.addChild(child2);
tx.commit();
s.close();
-
+
assertInsertCount(3);
assertUpdateCount(0);
}
-
+
public void testCreateException() {
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -90,7 +118,7 @@
s.persist(dupe);
tx.commit();
s.close();
-
+
s = openSession();
tx = s.beginTransaction();
s.persist(dupe);
@@ -103,10 +131,10 @@
}
tx.rollback();
s.close();
-
+
Node nondupe = new Node("nondupe");
nondupe.addChild(dupe);
-
+
s = openSession();
tx = s.beginTransaction();
s.persist(nondupe);
@@ -120,7 +148,7 @@
tx.rollback();
s.close();
}
-
+
public void testCreateExceptionWithGeneratedId() {
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -129,7 +157,7 @@
s.persist(dupe);
tx.commit();
s.close();
-
+
s = openSession();
tx = s.beginTransaction();
try {
@@ -141,10 +169,10 @@
}
tx.rollback();
s.close();
-
+
NumberedNode nondupe = new NumberedNode("nondupe");
nondupe.addChild(dupe);
-
+
s = openSession();
tx = s.beginTransaction();
try {
@@ -186,40 +214,5 @@
tx.commit();
s.close();
}
-
- private void clearCounts() {
- getSessions().getStatistics().clear();
- }
-
- private void assertInsertCount(int count) {
- int inserts = (int) getSessions().getStatistics().getEntityInsertCount();
- assertEquals(count, inserts);
- }
-
- private void assertUpdateCount(int count) {
- int updates = (int) getSessions().getStatistics().getEntityUpdateCount();
- assertEquals(count, updates);
- }
-
- protected void configure(Configuration cfg) {
- cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
- cfg.setProperty(Environment.STATEMENT_BATCH_SIZE, "0");
- }
-
- protected String[] getMappings() {
- return new String[] {
- "ops/Node.hbm.xml",
- "ops/Employer.hbm.xml"
- };
- }
-
- public static Test suite() {
- return new TestSuite(CreateTest.class);
- }
-
- public String getCacheConcurrencyStrategy() {
- return null;
- }
-
}
Added: trunk/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java 2006-11-07 23:50:28 UTC
(rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java 2006-11-08 00:00:53 UTC
(rev 10759)
@@ -0,0 +1,91 @@
+package org.hibernate.test.ops;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class DeleteTest extends AbstractOperationTestCase {
+ public DeleteTest(String name) {
+ super( name );
+ }
+
+ public static Test suite() {
+ return new TestSuite( DeleteTest.class );
+ }
+
+ public void testDeleteVersionedWithCollectionNoUpdate() {
+ // test adapted from HHH-1564...
+ Session s = openSession();
+ s.beginTransaction();
+ VersionedEntity c = new VersionedEntity( "c1", "child-1" );
+ VersionedEntity p = new VersionedEntity( "root", "root");
+ p.getChildren().add( c );
+ c.setParent( p );
+ s.save( p );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ VersionedEntity loadedParent = ( VersionedEntity ) s.get( VersionedEntity.class,
"root" );
+ s.delete( loadedParent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertInsertCount( 0 );
+ assertUpdateCount( 0 );
+ assertDeleteCount( 2 );
+ }
+
+ public void testNoUpdateOnDelete() {
+ Session s = openSession();
+ s.beginTransaction();
+ Node node = new Node( "test" );
+ s.persist( node );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( node );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ }
+
+ public void testNoUpdateOnDeleteWithCollection() {
+ Session s = openSession();
+ s.beginTransaction();
+ Node parent = new Node( "parent" );
+ Node child = new Node( "child" );
+ parent.getCascadingChildren().add( child );
+ s.persist( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ parent = ( Node ) s.get( Node.class, "parent" );
+ s.delete( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ assertDeleteCount( 2 );
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-07 23:50:28 UTC
(rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-08 00:00:53 UTC
(rev 10759)
@@ -2,7 +2,6 @@
package org.hibernate.test.ops;
import java.util.ArrayList;
-import java.util.Date;
import java.util.Iterator;
import junit.framework.Test;
@@ -12,20 +11,21 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.NonUniqueObjectException;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
-import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
-public class MergeTest extends TestCase {
-
+public class MergeTest extends AbstractOperationTestCase {
+
public MergeTest(String str) {
- super(str);
+ super( str );
}
+ public static Test suite() {
+ return new TestSuite( MergeTest.class );
+ }
+
public void testNoExtraUpdatesOnMerge() throws Exception {
Session s = openSession();
s.beginTransaction();
@@ -206,11 +206,7 @@
tx.commit();
s.close();
- s = openSession();
- tx = s.beginTransaction();
- s.delete( entity );
- tx.commit();
- s.close();
+ cleanup();
}
public void testPersistThenMergeInSameTxnWithTimestamp() {
@@ -232,17 +228,13 @@
tx.commit();
s.close();
- s = openSession();
- tx = s.beginTransaction();
- s.delete( entity );
- tx.commit();
- s.close();
+ cleanup();
}
public void testMergeDeepTree() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
Node root = new Node("root");
@@ -253,11 +245,11 @@
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(3);
assertUpdateCount(0);
clearCounts();
-
+
grandchild.setDescription("the grand child");
Node grandchild2 = new Node("grandchild2");
child.addChild( grandchild2 );
@@ -267,26 +259,26 @@
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(1);
assertUpdateCount(1);
clearCounts();
-
+
Node child2 = new Node("child2");
Node grandchild3 = new Node("grandchild3");
child2.addChild( grandchild3 );
root.addChild(child2);
-
+
s = openSession();
tx = s.beginTransaction();
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
assertUpdateCount(0);
clearCounts();
-
+
s = openSession();
tx = s.beginTransaction();
s.delete(grandchild);
@@ -297,13 +289,13 @@
s.delete(root);
tx.commit();
s.close();
-
+
}
-
+
public void testMergeDeepTreeWithGeneratedId() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
NumberedNode root = new NumberedNode("root");
@@ -314,11 +306,11 @@
root = (NumberedNode) s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(3);
assertUpdateCount(0);
clearCounts();
-
+
child = (NumberedNode) root.getChildren().iterator().next();
grandchild = (NumberedNode) child.getChildren().iterator().next();
grandchild.setDescription("the grand child");
@@ -330,28 +322,28 @@
root = (NumberedNode) s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(1);
assertUpdateCount(1);
clearCounts();
-
+
getSessions().evict(NumberedNode.class);
-
+
NumberedNode child2 = new NumberedNode("child2");
NumberedNode grandchild3 = new NumberedNode("grandchild3");
child2.addChild( grandchild3 );
root.addChild(child2);
-
+
s = openSession();
tx = s.beginTransaction();
root = (NumberedNode) s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
assertUpdateCount(0);
clearCounts();
-
+
s = openSession();
tx = s.beginTransaction();
s.createQuery("delete from NumberedNode where name like
'grand%'").executeUpdate();
@@ -359,13 +351,13 @@
s.createQuery("delete from NumberedNode").executeUpdate();
tx.commit();
s.close();
-
+
}
-
+
public void testMergeTree() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
Node root = new Node("root");
@@ -374,39 +366,33 @@
s.persist(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
clearCounts();
-
+
root.setDescription("The root node");
child.setDescription("The child node");
-
+
Node secondChild = new Node("second child");
-
+
root.addChild(secondChild);
-
+
s = openSession();
tx = s.beginTransaction();
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(1);
assertUpdateCount(2);
-
- s = openSession();
- tx = s.beginTransaction();
- s.createQuery("delete from Node where parent is not null").executeUpdate();
- s.createQuery("delete from Node").executeUpdate();
- tx.commit();
- s.close();
-
+
+ cleanup();
}
-
+
public void testMergeTreeWithGeneratedId() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
NumberedNode root = new NumberedNode("root");
@@ -415,45 +401,39 @@
s.persist(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
clearCounts();
-
+
root.setDescription("The root node");
child.setDescription("The child node");
-
+
NumberedNode secondChild = new NumberedNode("second child");
-
+
root.addChild(secondChild);
-
+
s = openSession();
tx = s.beginTransaction();
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(1);
assertUpdateCount(2);
-
- s = openSession();
- tx = s.beginTransaction();
- s.createQuery("delete from NumberedNode where parent is not
null").executeUpdate();
- s.createQuery("delete from NumberedNode").executeUpdate();
- tx.commit();
- s.close();
+ cleanup();
}
-
+
public void testMergeManaged() {
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
NumberedNode root = new NumberedNode("root");
s.persist(root);
tx.commit();
-
+
clearCounts();
-
+
tx = s.beginTransaction();
NumberedNode child = new NumberedNode("child");
root.addChild(child);
@@ -466,27 +446,24 @@
assertTrue( root.getChildren().contains(mergedChild) );
//assertNotSame( mergedChild, s.merge(child) ); //yucky :(
tx.commit();
-
+
assertInsertCount(1);
assertUpdateCount(0);
-
+
assertEquals( root.getChildren().size(), 1 );
assertTrue( root.getChildren().contains(mergedChild) );
-
+
tx = s.beginTransaction();
- assertEquals(
+ assertEquals(
s.createCriteria(NumberedNode.class)
.setProjection( Projections.rowCount() )
- .uniqueResult(),
- new Integer(2)
+ .uniqueResult(),
+ new Integer(2)
);
- s.delete(root);
- s.delete(mergedChild);
- tx.commit();
- s.close();
-
+
+ cleanup();
}
-
+
public void testRecursiveMergeTransient() {
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -502,7 +479,9 @@
s.clear();
s.merge( jboss.getEmployees().iterator().next() );
tx.commit();
- s.close();
+ s.close();
+
+ cleanup();
}
public void testDeleteAndMerge() throws Exception {
@@ -524,22 +503,10 @@
s.merge( jboss );
s.getTransaction().commit();
s.close();
- }
-
- private void clearCounts() {
- getSessions().getStatistics().clear();
- }
- private void assertInsertCount(int expected) {
- int inserts = (int) getSessions().getStatistics().getEntityInsertCount();
- assertEquals( "unexpected insert count", expected, inserts );
+ cleanup();
}
- private void assertUpdateCount(int expected) {
- int updates = (int) getSessions().getStatistics().getEntityUpdateCount();
- assertEquals( "unexpected update counts", expected, updates );
- }
-
private void cleanup() {
Session s = openSession();
s.beginTransaction();
@@ -560,19 +527,5 @@
s.getTransaction().commit();
s.close();
}
-
- protected void configure(Configuration cfg) {
- cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
- cfg.setProperty(Environment.STATEMENT_BATCH_SIZE, "0");
- }
-
- protected String[] getMappings() {
- return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml",
"ops/OptLockEntity.hbm.xml" };
- }
-
- public static Test suite() {
- return new TestSuite(MergeTest.class);
- }
-
}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml 2006-11-07 23:50:28 UTC (rev
10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml 2006-11-08 00:00:53 UTC (rev
10759)
@@ -1,14 +1,14 @@
<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
+<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
-
+
-->
<hibernate-mapping package="org.hibernate.test.ops">
-
+
<class name="Node" polymorphism="explicit">
<id name="name">
<generator class="assigned"/>
@@ -16,15 +16,18 @@
<property name="description"/>
<many-to-one name="parent"/>
<property name="created" not-null="true"/>
- <set name="children"
+ <set name="children"
inverse="true"
cascade="persist,merge,save-update,evict">
<key column="parent"/>
<one-to-many class="Node"/>
</set>
-
- </class>
-
+ <set name="cascadingChildren" inverse="false"
cascade="persist,merge,save-update,evict,delete">
+ <key column="CASC_PARENT"/>
+ <one-to-many class="Node"/>
+ </set>
+ </class>
+
<class name="NumberedNode" polymorphism="explicit">
<id name="id" unsaved-value="0">
<generator class="native"/>
@@ -36,13 +39,13 @@
<property name="created" not-null="true"
type="imm_date"/>
<many-to-one name="parent" class="NumberedNode"/>
- <set name="children"
+ <set name="children"
inverse="true"
cascade="persist,merge,save-update">
<key column="parent"/>
<one-to-many class="NumberedNode"/>
</set>
</class>
-
+
</hibernate-mapping>
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/Node.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Node.java 2006-11-07 23:50:28 UTC (rev
10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Node.java 2006-11-08 00:00:53 UTC (rev
10759)
@@ -9,47 +9,34 @@
* @author Gavin King
*/
public class Node {
-
+
private String name;
+ private String description;
+ private Date created;
private Node parent;
private Set children = new HashSet();
- private String description;
- private Date created;
-
- public Node() {}
-
+ private Set cascadingChildren = new HashSet();
+
+ public Node() {
+ }
+
public Node(String name) {
this.name = name;
created = generateCurrentDate();
}
- public Set getChildren() {
- return children;
- }
- public void setChildren(Set children) {
- this.children = children;
- }
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
- public Node getParent() {
- return parent;
- }
- public void setParent(Node parent) {
- this.parent = parent;
- }
-
- public Node addChild(Node child) {
- children.add(child);
- child.setParent(this);
- return this;
- }
+
public String getDescription() {
return description;
}
+
public void setDescription(String description) {
this.description = description;
}
@@ -62,6 +49,36 @@
this.created = created;
}
+ public Node getParent() {
+ return parent;
+ }
+
+ public void setParent(Node parent) {
+ this.parent = parent;
+ }
+
+ public Set getChildren() {
+ return children;
+ }
+
+ public void setChildren(Set children) {
+ this.children = children;
+ }
+
+ public Node addChild(Node child) {
+ children.add( child );
+ child.setParent( this );
+ return this;
+ }
+
+ public Set getCascadingChildren() {
+ return cascadingChildren;
+ }
+
+ public void setCascadingChildren(Set cascadingChildren) {
+ this.cascadingChildren = cascadingChildren;
+ }
+
private Date generateCurrentDate() {
// Note : done as java.sql.Date mainly to work around issue with
// MySQL and its lack of milli-second precision on its DATETIME
Added: trunk/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java 2006-11-07 23:50:28 UTC
(rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java 2006-11-08 00:00:53 UTC
(rev 10759)
@@ -0,0 +1,21 @@
+package org.hibernate.test.ops;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class OpsSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "Operations tests" );
+ suite.addTest( CreateTest.suite() );
+ suite.addTest( DeleteTest.suite() );
+ suite.addTest( GetLoadTest.suite() );
+ suite.addTest( MergeTest.suite() );
+ suite.addTest( SaveOrUpdateTest.suite() );
+ return suite;
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-07 23:50:28
UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-08 00:00:53
UTC (rev 10759)
@@ -1,10 +1,10 @@
<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
+<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
-
+
-->
<hibernate-mapping package="org.hibernate.test.ops">
@@ -18,7 +18,7 @@
<many-to-one name="parent" class="VersionedEntity"/>
<set name="children"
inverse="true"
- cascade="persist,merge,save-update,evict">
+ cascade="persist,merge,save-update,evict,delete">
<key column="parent"/>
<one-to-many class="VersionedEntity"/>
</set>