Hibernate SVN: r10741 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/type test/org/hibernate/test/ops
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-06 17:14:32 -0500 (Mon, 06 Nov 2006)
New Revision: 10741
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/type/CollectionType.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/VersionedEntity.java
Log:
HHH-1401 : merge operation casuing unecessary updates
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/type/CollectionType.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/type/CollectionType.java 2006-11-06 22:13:39 UTC (rev 10740)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/type/CollectionType.java 2006-11-06 22:14:32 UTC (rev 10741)
@@ -397,15 +397,25 @@
}
/**
- * Replace the elements of a collection with the elements of another collection
+ * Replace the elements of a collection with the elements of another collection.
+ *
+ * @param original The 'source' of the replacement elements (where we copy from)
+ * @param target The target of the replacement elements (where we copy to)
+ * @param owner The owner of the collection being merged
+ * @param copyCache The map of elements already replaced.
+ * @param session The session from which the merge event originated.
+ * @return The merged collection.
*/
- public Object replaceElements(Object original, Object target, Object owner, Map copyCache,
- SessionImplementor session) throws HibernateException {
-
+ public Object replaceElements(
+ Object original,
+ Object target,
+ Object owner,
+ Map copyCache,
+ SessionImplementor session) {
// TODO: does not work for EntityMode.DOM4J yet!
-
- java.util.Collection result = (java.util.Collection) target;
-
+ java.util.Collection result = ( java.util.Collection ) target;
+ final boolean isPC = ( result instanceof PersistentCollection );
+ final boolean wasOriginalDirty = ( original instanceof PersistentCollection && ( ( PersistentCollection ) original ).isDirty() );
result.clear();
// copy elements into newly empty target collection
@@ -414,9 +424,12 @@
while ( iter.hasNext() ) {
result.add( elemType.replace( iter.next(), null, session, owner, copyCache ) );
}
-
+
+ if ( result instanceof PersistentCollection && !wasOriginalDirty ) {
+ ( ( PersistentCollection ) result ).clearDirty();
+ }
+
return result;
-
}
/**
@@ -439,24 +452,25 @@
*
* @param anticipatedSize The anticipated size of the instaniated collection
* after we are done populating it.
+ * @return A newly instantiated collection to be wrapped.
*/
public abstract Object instantiate(int anticipatedSize);
+ /**
+ * {@inheritDoc}
+ */
public Object replace(
final Object original,
final Object target,
final SessionImplementor session,
final Object owner,
- final Map copyCache)
- throws HibernateException {
-
+ final Map copyCache) throws HibernateException {
if ( original == null ) {
return null;
}
if ( !Hibernate.isInitialized( original ) ) {
return target;
}
- //if ( original == target ) return target; // can't do this, since need to merge element references
// for a null target, or a target which is the same as the original, we
// need to put the merged elements in a new collection
@@ -475,7 +489,6 @@
}
return result;
-
}
/**
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-06 22:13:39 UTC (rev 10740)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-06 22:14:32 UTC (rev 10741)
@@ -2,6 +2,7 @@
package org.hibernate.test.ops;
import java.util.ArrayList;
+import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -24,6 +25,167 @@
super(str);
}
+ public void testNoExtraUpdatesOnMerge() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ Node node = new Node( "test" );
+ s.persist( node );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // node is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ node = ( Node ) s.merge( node );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node while it is detached and
+ // make sure we get an update as a result...
+ node.setDescription( "new description" );
+ s = openSession();
+ s.beginTransaction();
+ node = ( Node ) s.merge( node );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 0 );
+ ///////////////////////////////////////////////////////////////////////
+
+ cleanup();
+ }
+
+ public void testNoExtraUpdatesOnMergeWithCollection() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ Node parent = new Node( "parent" );
+ Node child = new Node( "child" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ s.persist( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // parent is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ parent = ( Node ) s.merge( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node while it is detached and
+ // make sure we get an update as a result...
+ ( ( Node ) parent.getChildren().iterator().next() ).setDescription( "child's new description" );
+ parent.getChildren().add( new Node( "second child" ) );
+ s = openSession();
+ s.beginTransaction();
+ parent = ( Node ) s.merge( parent );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 1 );
+ ///////////////////////////////////////////////////////////////////////
+
+ cleanup();
+ }
+
+ public void testNoExtraUpdatesOnMergeVersioned() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ VersionedEntity entity = new VersionedEntity( "entity", "entity" );
+ s.persist( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // entity is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ VersionedEntity mergedEntity = ( VersionedEntity ) s.merge( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ assertEquals( "unexpected version increment", entity.getVersion(), mergedEntity.getVersion() );
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node while it is detached and
+ // make sure we get an update as a result...
+ entity.setName( "new name" );
+ s = openSession();
+ s.beginTransaction();
+ entity = ( VersionedEntity ) s.merge( entity );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 0 );
+ ///////////////////////////////////////////////////////////////////////
+
+ cleanup();
+ }
+
+ public void testNoExtraUpdatesOnMergeVersionedWithCollection() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ VersionedEntity parent = new VersionedEntity( "parent", "parent" );
+ VersionedEntity child = new VersionedEntity( "child", "child" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ s.persist( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // parent is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ VersionedEntity mergedParent = ( VersionedEntity ) s.merge( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ assertEquals( "unexpected parent version increment", parent.getVersion(), mergedParent.getVersion() );
+ VersionedEntity mergedChild = ( VersionedEntity ) mergedParent.getChildren().iterator().next();
+ assertEquals( "unexpected child version increment", child.getVersion(), mergedChild.getVersion() );
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node while it is detached and
+ // make sure we get an update as a result...
+ mergedParent.setName( "new name" );
+ mergedParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
+ s = openSession();
+ s.beginTransaction();
+ parent = ( VersionedEntity ) s.merge( mergedParent );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 1 );
+ ///////////////////////////////////////////////////////////////////////
+
+ cleanup();
+ }
+
public void testPersistThenMergeInSameTxnWithVersion() {
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -43,11 +205,7 @@
tx.commit();
s.close();
- s = openSession();
- tx = s.beginTransaction();
- s.delete( entity );
- tx.commit();
- s.close();
+ cleanup();
}
public void testPersistThenMergeInSameTxnWithTimestamp() {
@@ -69,11 +227,7 @@
tx.commit();
s.close();
- s = openSession();
- tx = s.beginTransaction();
- s.delete( entity );
- tx.commit();
- s.close();
+ cleanup();
}
public void testMergeDeepTree() {
@@ -123,7 +277,7 @@
assertInsertCount(2);
assertUpdateCount(0);
clearCounts();
-
+
s = openSession();
tx = s.beginTransaction();
s.delete(grandchild);
@@ -134,7 +288,7 @@
s.delete(root);
tx.commit();
s.close();
-
+
}
public void testMergeDeepTreeWithGeneratedId() {
@@ -188,7 +342,7 @@
assertInsertCount(2);
assertUpdateCount(0);
clearCounts();
-
+
s = openSession();
tx = s.beginTransaction();
s.createQuery("delete from NumberedNode where name like 'grand%'").executeUpdate();
@@ -196,7 +350,7 @@
s.createQuery("delete from NumberedNode").executeUpdate();
tx.commit();
s.close();
-
+
}
public void testMergeTree() {
@@ -230,14 +384,8 @@
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() {
@@ -271,14 +419,8 @@
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() {
@@ -317,11 +459,8 @@
.uniqueResult(),
new Integer(2)
);
- s.delete(root);
- s.delete(mergedChild);
- tx.commit();
- s.close();
-
+
+ cleanup();
}
public void testRecursiveMergeTransient() {
@@ -339,7 +478,9 @@
s.clear();
s.merge( jboss.getEmployees().iterator().next() );
tx.commit();
- s.close();
+ s.close();
+
+ cleanup();
}
public void testDeleteAndMerge() throws Exception {
@@ -361,20 +502,22 @@
s.merge( jboss );
s.getTransaction().commit();
s.close();
+
+ cleanup();
}
private void clearCounts() {
getSessions().getStatistics().clear();
}
- private void assertInsertCount(int count) {
+ private void assertInsertCount(int expected) {
int inserts = (int) getSessions().getStatistics().getEntityInsertCount();
- assertEquals(count, inserts);
+ assertEquals( "unexpected insert count", expected, inserts );
}
- private void assertUpdateCount(int count) {
+ private void assertUpdateCount(int expected) {
int updates = (int) getSessions().getStatistics().getEntityUpdateCount();
- assertEquals(count, updates);
+ assertEquals( "unexpected update counts", expected, updates );
}
protected void configure(Configuration cfg) {
@@ -390,5 +533,25 @@
return new TestSuite(MergeTest.class);
}
+ private void cleanup() {
+ Session s = openSession();
+ s.beginTransaction();
+ s.createQuery("delete from NumberedNode where parent is not null").executeUpdate();
+ s.createQuery("delete from NumberedNode").executeUpdate();
+ s.createQuery("delete from Node where parent is not null").executeUpdate();
+ s.createQuery("delete from Node").executeUpdate();
+ s.createQuery("delete from VersionedEntity where parent is not null").executeUpdate();
+ s.createQuery("delete from VersionedEntity").executeUpdate();
+ s.createQuery("delete from TimestampedEntity").executeUpdate();
+
+ Iterator itr = s.createQuery( "from Employer" ).list().iterator();
+ while ( itr.hasNext() ) {
+ final Employer employer = ( Employer ) itr.next();
+ s.delete( employer );
+ }
+
+ s.getTransaction().commit();
+ s.close();
+ }
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-06 22:13:39 UTC (rev 10740)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-06 22:14:32 UTC (rev 10741)
@@ -15,6 +15,13 @@
</id>
<version name="version" column="VERS" type="long" />
<property name="name" column="NAME" type="string" />
+ <many-to-one name="parent" class="VersionedEntity"/>
+ <set name="children"
+ inverse="true"
+ cascade="persist,merge,save-update,evict">
+ <key column="parent"/>
+ <one-to-many class="VersionedEntity"/>
+ </set>
</class>
<class name="TimestampedEntity" table="T_ENTITY">
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/VersionedEntity.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/VersionedEntity.java 2006-11-06 22:13:39 UTC (rev 10740)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/VersionedEntity.java 2006-11-06 22:14:32 UTC (rev 10741)
@@ -1,7 +1,10 @@
package org.hibernate.test.ops;
+import java.util.Set;
+import java.util.HashSet;
+
/**
- * todo: describe VersionedEntity
+ * VersionedEntity
*
* @author Steve Ebersole
*/
@@ -10,6 +13,9 @@
private String name;
private long version;
+ private VersionedEntity parent;
+ private Set children = new HashSet();
+
public VersionedEntity() {
}
@@ -41,4 +47,20 @@
public void setVersion(long version) {
this.version = version;
}
+
+ public VersionedEntity getParent() {
+ return parent;
+ }
+
+ public void setParent(VersionedEntity parent) {
+ this.parent = parent;
+ }
+
+ public Set getChildren() {
+ return children;
+ }
+
+ public void setChildren(Set children) {
+ this.children = children;
+ }
}
18 years, 2 months
Hibernate SVN: r10740 - in trunk/Hibernate3: src/org/hibernate/type test/org/hibernate/test/ops
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-06 17:13:39 -0500 (Mon, 06 Nov 2006)
New Revision: 10740
Modified:
trunk/Hibernate3/src/org/hibernate/type/CollectionType.java
trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/ops/VersionedEntity.java
Log:
HHH-1401 : merge operation casuing unecessary updates
Modified: trunk/Hibernate3/src/org/hibernate/type/CollectionType.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/type/CollectionType.java 2006-11-06 22:00:41 UTC (rev 10739)
+++ trunk/Hibernate3/src/org/hibernate/type/CollectionType.java 2006-11-06 22:13:39 UTC (rev 10740)
@@ -397,15 +397,25 @@
}
/**
- * Replace the elements of a collection with the elements of another collection
+ * Replace the elements of a collection with the elements of another collection.
+ *
+ * @param original The 'source' of the replacement elements (where we copy from)
+ * @param target The target of the replacement elements (where we copy to)
+ * @param owner The owner of the collection being merged
+ * @param copyCache The map of elements already replaced.
+ * @param session The session from which the merge event originated.
+ * @return The merged collection.
*/
- public Object replaceElements(Object original, Object target, Object owner, Map copyCache,
- SessionImplementor session) throws HibernateException {
-
+ public Object replaceElements(
+ Object original,
+ Object target,
+ Object owner,
+ Map copyCache,
+ SessionImplementor session) {
// TODO: does not work for EntityMode.DOM4J yet!
-
- java.util.Collection result = (java.util.Collection) target;
-
+ java.util.Collection result = ( java.util.Collection ) target;
+ final boolean isPC = ( result instanceof PersistentCollection );
+ final boolean wasOriginalDirty = ( original instanceof PersistentCollection && ( ( PersistentCollection ) original ).isDirty() );
result.clear();
// copy elements into newly empty target collection
@@ -414,9 +424,12 @@
while ( iter.hasNext() ) {
result.add( elemType.replace( iter.next(), null, session, owner, copyCache ) );
}
-
+
+ if ( result instanceof PersistentCollection && !wasOriginalDirty ) {
+ ( ( PersistentCollection ) result ).clearDirty();
+ }
+
return result;
-
}
/**
@@ -439,24 +452,25 @@
*
* @param anticipatedSize The anticipated size of the instaniated collection
* after we are done populating it.
+ * @return A newly instantiated collection to be wrapped.
*/
public abstract Object instantiate(int anticipatedSize);
+ /**
+ * {@inheritDoc}
+ */
public Object replace(
- final Object original,
+ final Object original,
final Object target,
- final SessionImplementor session,
- final Object owner,
- final Map copyCache)
- throws HibernateException {
-
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache) throws HibernateException {
if ( original == null ) {
return null;
}
if ( !Hibernate.isInitialized( original ) ) {
return target;
}
- //if ( original == target ) return target; // can't do this, since need to merge element references
// for a null target, or a target which is the same as the original, we
// need to put the merged elements in a new collection
@@ -465,7 +479,7 @@
//for arrays, replaceElements() may return a different reference, since
//the array length might not match
result = replaceElements( original, result, owner, copyCache, session );
-
+
if (original==target) {
//get the elements back into the target
//TODO: this is a little inefficient, don't need to do a whole
@@ -473,9 +487,8 @@
replaceElements( result, target, owner, copyCache, session );
result = target;
}
-
+
return result;
-
}
/**
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-06 22:00:41 UTC (rev 10739)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-06 22:13:39 UTC (rev 10740)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -25,6 +26,167 @@
super(str);
}
+ public void testNoExtraUpdatesOnMerge() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ Node node = new Node( "test" );
+ s.persist( node );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // node is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ node = ( Node ) s.merge( node );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node while it is detached and
+ // make sure we get an update as a result...
+ node.setDescription( "new description" );
+ s = openSession();
+ s.beginTransaction();
+ node = ( Node ) s.merge( node );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 0 );
+ ///////////////////////////////////////////////////////////////////////
+
+ cleanup();
+ }
+
+ public void testNoExtraUpdatesOnMergeWithCollection() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ Node parent = new Node( "parent" );
+ Node child = new Node( "child" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ s.persist( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // parent is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ parent = ( Node ) s.merge( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node while it is detached and
+ // make sure we get an update as a result...
+ ( ( Node ) parent.getChildren().iterator().next() ).setDescription( "child's new description" );
+ parent.getChildren().add( new Node( "second child" ) );
+ s = openSession();
+ s.beginTransaction();
+ parent = ( Node ) s.merge( parent );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 1 );
+ ///////////////////////////////////////////////////////////////////////
+
+ cleanup();
+ }
+
+ public void testNoExtraUpdatesOnMergeVersioned() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ VersionedEntity entity = new VersionedEntity( "entity", "entity" );
+ s.persist( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // entity is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ VersionedEntity mergedEntity = ( VersionedEntity ) s.merge( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ assertEquals( "unexpected version increment", entity.getVersion(), mergedEntity.getVersion() );
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node while it is detached and
+ // make sure we get an update as a result...
+ entity.setName( "new name" );
+ s = openSession();
+ s.beginTransaction();
+ entity = ( VersionedEntity ) s.merge( entity );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 0 );
+ ///////////////////////////////////////////////////////////////////////
+
+ cleanup();
+ }
+
+ public void testNoExtraUpdatesOnMergeVersionedWithCollection() throws Exception {
+ Session s = openSession();
+ s.beginTransaction();
+ VersionedEntity parent = new VersionedEntity( "parent", "parent" );
+ VersionedEntity child = new VersionedEntity( "child", "child" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ s.persist( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ // parent is now detached, but we have made no changes. so attempt to merge it
+ // into this new session; this should cause no updates...
+ s = openSession();
+ s.beginTransaction();
+ VersionedEntity mergedParent = ( VersionedEntity ) s.merge( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ assertEquals( "unexpected parent version increment", parent.getVersion(), mergedParent.getVersion() );
+ VersionedEntity mergedChild = ( VersionedEntity ) mergedParent.getChildren().iterator().next();
+ assertEquals( "unexpected child version increment", child.getVersion(), mergedChild.getVersion() );
+
+ ///////////////////////////////////////////////////////////////////////
+ // as a control measure, now update the node while it is detached and
+ // make sure we get an update as a result...
+ mergedParent.setName( "new name" );
+ mergedParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
+ s = openSession();
+ s.beginTransaction();
+ parent = ( VersionedEntity ) s.merge( mergedParent );
+ s.getTransaction().commit();
+ s.close();
+ assertUpdateCount( 1 );
+ assertInsertCount( 1 );
+ ///////////////////////////////////////////////////////////////////////
+
+ cleanup();
+ }
+
public void testPersistThenMergeInSameTxnWithVersion() {
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -367,16 +529,37 @@
private void clearCounts() {
getSessions().getStatistics().clear();
}
-
- private void assertInsertCount(int count) {
+
+ private void assertInsertCount(int expected) {
int inserts = (int) getSessions().getStatistics().getEntityInsertCount();
- assertEquals(count, inserts);
+ assertEquals( "unexpected insert count", expected, inserts );
}
-
- private void assertUpdateCount(int count) {
+
+ private void assertUpdateCount(int expected) {
int updates = (int) getSessions().getStatistics().getEntityUpdateCount();
- assertEquals(count, updates);
+ assertEquals( "unexpected update counts", expected, updates );
}
+
+ private void cleanup() {
+ Session s = openSession();
+ s.beginTransaction();
+ s.createQuery("delete from NumberedNode where parent is not null").executeUpdate();
+ s.createQuery("delete from NumberedNode").executeUpdate();
+ s.createQuery("delete from Node where parent is not null").executeUpdate();
+ s.createQuery("delete from Node").executeUpdate();
+ s.createQuery("delete from VersionedEntity where parent is not null").executeUpdate();
+ s.createQuery("delete from VersionedEntity").executeUpdate();
+ s.createQuery("delete from TimestampedEntity").executeUpdate();
+
+ Iterator itr = s.createQuery( "from Employer" ).list().iterator();
+ while ( itr.hasNext() ) {
+ final Employer employer = ( Employer ) itr.next();
+ s.delete( employer );
+ }
+
+ s.getTransaction().commit();
+ s.close();
+ }
protected void configure(Configuration cfg) {
cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-06 22:00:41 UTC (rev 10739)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-06 22:13:39 UTC (rev 10740)
@@ -15,6 +15,13 @@
</id>
<version name="version" column="VERS" type="long" />
<property name="name" column="NAME" type="string" />
+ <many-to-one name="parent" class="VersionedEntity"/>
+ <set name="children"
+ inverse="true"
+ cascade="persist,merge,save-update,evict">
+ <key column="parent"/>
+ <one-to-many class="VersionedEntity"/>
+ </set>
</class>
<class name="TimestampedEntity" table="T_ENTITY">
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/VersionedEntity.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/VersionedEntity.java 2006-11-06 22:00:41 UTC (rev 10739)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/VersionedEntity.java 2006-11-06 22:13:39 UTC (rev 10740)
@@ -1,7 +1,10 @@
package org.hibernate.test.ops;
+import java.util.Set;
+import java.util.HashSet;
+
/**
- * todo: describe VersionedEntity
+ * VersionedEntity
*
* @author Steve Ebersole
*/
@@ -10,6 +13,9 @@
private String name;
private long version;
+ private VersionedEntity parent;
+ private Set children = new HashSet();
+
public VersionedEntity() {
}
@@ -41,4 +47,20 @@
public void setVersion(long version) {
this.version = version;
}
+
+ public VersionedEntity getParent() {
+ return parent;
+ }
+
+ public void setParent(VersionedEntity parent) {
+ this.parent = parent;
+ }
+
+ public Set getChildren() {
+ return children;
+ }
+
+ public void setChildren(Set children) {
+ this.children = children;
+ }
}
18 years, 2 months
Hibernate SVN: r10739 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/collection test/org/hibernate/test/collection test/org/hibernate/test/collection/bag test/org/hibernate/test/collection/idbag test/org/hibernate/test/collection/list
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-06 17:00:41 -0500 (Mon, 06 Nov 2006)
New Revision: 10739
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentBag.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentList.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java
Log:
HHH-2217 : PersistentCollection mutation methods and dirtying
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentBag.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentBag.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentBag.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -284,8 +284,14 @@
* @see java.util.Collection#remove(Object)
*/
public boolean remove(Object o) {
- write();
- return bag.remove(o);
+ initialize( true );
+ if ( bag.remove( o ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -319,8 +325,14 @@
*/
public boolean removeAll(Collection c) {
if ( c.size()>0 ) {
- write();
- return bag.removeAll(c);
+ initialize( true );
+ if ( bag.removeAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else {
return false;
@@ -331,8 +343,14 @@
* @see java.util.Collection#retainAll(Collection)
*/
public boolean retainAll(Collection c) {
- write();
- return bag.retainAll(c);
+ initialize( true );
+ if ( bag.retainAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -343,8 +361,11 @@
queueOperation( new Clear() );
}
else {
- write();
- bag.clear();
+ initialize( true );
+ if ( ! bag.isEmpty() ) {
+ bag.clear();
+ dirty();
+ }
}
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -88,9 +88,12 @@
}
public void clear() {
- write();
- values.clear();
- identifiers.clear();
+ initialize( true );
+ if ( ! values.isEmpty() || ! identifiers.isEmpty() ) {
+ values.clear();
+ identifiers.clear();
+ dirty();
+ }
}
public boolean contains(Object o) {
@@ -113,11 +116,12 @@
}
public boolean remove(Object o) {
- write();
+ initialize( true );
int index = values.indexOf(o);
if (index>=0) {
beforeRemove(index);
values.remove(index);
+ dirty();
return true;
}
else {
@@ -126,9 +130,7 @@
}
public boolean removeAll(Collection c) {
- if ( c.size()>0 ) {
- //write();
- //return values.removeAll(c);
+ if ( c.size() > 0 ) {
boolean result = false;
Iterator iter = c.iterator();
while ( iter.hasNext() ) {
@@ -142,8 +144,14 @@
}
public boolean retainAll(Collection c) {
- write();
- return values.retainAll(c);
+ initialize( true );
+ if ( values.retainAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
public int size() {
@@ -308,11 +316,11 @@
}
public boolean addAll(int index, Collection c) {
- if ( c.size()>0 ) {
- //write();
- //return values.addAll(index, c);
+ if ( c.size() > 0 ) {
Iterator iter = c.iterator();
- while ( iter.hasNext() ) add( index++, iter.next() );
+ while ( iter.hasNext() ) {
+ add( index++, iter.next() );
+ }
return true;
}
else {
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentList.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentList.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentList.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -150,11 +150,16 @@
* @see java.util.List#remove(Object)
*/
public boolean remove(Object value) {
- Boolean exists = isPutQueueEnabled() ?
- readElementExistence(value) : null;
- if ( exists==null ) {
- write();
- return list.remove(value);
+ Boolean exists = isPutQueueEnabled() ? readElementExistence(value) : null;
+ if ( exists == null ) {
+ initialize( true );
+ if ( list.remove( value ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else if ( exists.booleanValue() ) {
queueOperation( new SimpleRemove(value) );
@@ -177,7 +182,9 @@
* @see java.util.List#addAll(Collection)
*/
public boolean addAll(Collection values) {
- if ( values.size()==0 ) return false;
+ if ( values.size()==0 ) {
+ return false;
+ }
if ( !isOperationQueueEnabled() ) {
write();
return list.addAll(values);
@@ -209,8 +216,14 @@
*/
public boolean removeAll(Collection coll) {
if ( coll.size()>0 ) {
- write();
- return list.removeAll(coll);
+ initialize( true );
+ if ( list.removeAll( coll ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else {
return false;
@@ -221,8 +234,14 @@
* @see java.util.List#retainAll(Collection)
*/
public boolean retainAll(Collection coll) {
- write();
- return list.retainAll(coll);
+ initialize( true );
+ if ( list.retainAll( coll ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -233,8 +252,11 @@
queueOperation( new Clear() );
}
else {
- write();
- list.clear();
+ initialize( true );
+ if ( ! list.isEmpty() ) {
+ list.clear();
+ dirty();
+ }
}
}
@@ -256,8 +278,7 @@
if (index<0) {
throw new ArrayIndexOutOfBoundsException("negative index");
}
- Object old = isPutQueueEnabled() ?
- readElementByIndex( new Integer(index) ) : UNKNOWN;
+ Object old = isPutQueueEnabled() ? readElementByIndex( new Integer(index) ) : UNKNOWN;
if ( old==UNKNOWN ) {
write();
return list.set(index, value);
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -2,11 +2,15 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+
+import org.hibernate.test.collection.bag.PersistentBagTest;
+import org.hibernate.test.collection.idbag.PersistentIdBagTest;
+import org.hibernate.test.collection.list.PersistentListTest;
import org.hibernate.test.collection.map.PersistentMapTest;
import org.hibernate.test.collection.set.PersistentSetTest;
/**
- * todo: describe CollectionSuite
+ * Suite of collection (esp PersistentCollection) related tests
*
* @author Steve Ebersole
*/
@@ -15,6 +19,9 @@
public static Test suite() {
TestSuite suite = new TestSuite( "Collection-related tests" );
suite.addTest( CollectionTest.suite() );
+ suite.addTest( PersistentBagTest.suite() );
+ suite.addTest( PersistentIdBagTest.suite() );
+ suite.addTest( PersistentListTest.suite() );
suite.addTest( PersistentMapTest.suite() );
suite.addTest( PersistentSetTest.suite() );
return suite;
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,46 @@
+package org.hibernate.test.collection.bag;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class BagOwner {
+ private String name;
+ private BagOwner parent;
+ private List children = new ArrayList();
+
+ public BagOwner() {
+ }
+
+ public BagOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public BagOwner getParent() {
+ return parent;
+ }
+
+ public void setParent(BagOwner parent) {
+ this.parent = parent;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<!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.collection.bag">
+
+ <class name="BagOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <many-to-one name="parent" class="BagOwner" cascade="none" />
+
+ <bag name="children" inverse="true" cascade="all">
+ <key column="PARENT" />
+ <one-to-many class="BagOwner" />
+ </bag>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,71 @@
+package org.hibernate.test.collection.bag;
+
+import java.util.HashSet;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentBag;
+
+/**
+ * Tests related to operations on a PersistentBag.
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentBagTest extends TestCase {
+ public PersistentBagTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/bag/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentBagTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ BagOwner parent = new BagOwner( "root" );
+ BagOwner child = new BagOwner( "c1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ BagOwner otherChild = new BagOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentBag...
+ PersistentBag children = ( PersistentBag ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,37 @@
+package org.hibernate.test.collection.idbag;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class IdbagOwner {
+ private String name;
+ private List children = new ArrayList();
+
+ public IdbagOwner() {
+ }
+
+ public IdbagOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!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.collection.idbag">
+
+ <class name="IdbagOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <idbag name="children" cascade="all" table="idbag_owner_children">
+ <collection-id column="CHILD" type="long">
+ <generator class="increment"/>
+ </collection-id>
+ <key column="PARENT_FK" />
+ <many-to-many column="CHILD_FK" class="IdbagOwner" />
+ </idbag>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,69 @@
+package org.hibernate.test.collection.idbag;
+
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentIdentifierBag;
+
+/**
+ * Tests related to operations on a PersistentIdentifierBag
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentIdBagTest extends TestCase {
+ public PersistentIdBagTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/idbag/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentIdBagTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ IdbagOwner parent = new IdbagOwner( "root" );
+ IdbagOwner child = new IdbagOwner( "c1" );
+ parent.getChildren().add( child );
+ IdbagOwner otherChild = new IdbagOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentBag...
+ PersistentIdentifierBag children = ( PersistentIdentifierBag ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,46 @@
+package org.hibernate.test.collection.list;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ListOwner {
+ private String name;
+ private ListOwner parent;
+ private List children = new ArrayList();
+
+ public ListOwner() {
+ }
+
+ public ListOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ListOwner getParent() {
+ return parent;
+ }
+
+ public void setParent(ListOwner parent) {
+ this.parent = parent;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!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.collection.list">
+
+ <class name="ListOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <many-to-one name="parent" class="ListOwner" cascade="none" />
+
+ <list name="children" inverse="true" cascade="all">
+ <key column="PARENT" />
+ <list-index column="LIST_INDEX"/>
+ <one-to-many class="ListOwner" />
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java 2006-11-06 21:56:38 UTC (rev 10738)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java 2006-11-06 22:00:41 UTC (rev 10739)
@@ -0,0 +1,70 @@
+package org.hibernate.test.collection.list;
+
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentList;
+
+/**
+ * Tests related to operations on a PersistentList
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentListTest extends TestCase {
+ public PersistentListTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/list/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentListTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ ListOwner parent = new ListOwner( "root" );
+ ListOwner child = new ListOwner( "c1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ ListOwner otherChild = new ListOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentList...
+ PersistentList children = ( PersistentList ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
18 years, 2 months
Hibernate SVN: r10738 - in trunk/Hibernate3: src/org/hibernate/collection test/org/hibernate/test/collection test/org/hibernate/test/collection/bag test/org/hibernate/test/collection/idbag test/org/hibernate/test/collection/list
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-06 16:56:38 -0500 (Mon, 06 Nov 2006)
New Revision: 10738
Added:
trunk/Hibernate3/test/org/hibernate/test/collection/bag/
trunk/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java
trunk/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java
trunk/Hibernate3/test/org/hibernate/test/collection/list/
trunk/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java
trunk/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java
Modified:
trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java
trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java
trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java
trunk/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java
Log:
HHH-2217 : PersistentCollection mutation methods and dirtying
Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -57,7 +57,7 @@
public boolean empty() {
return bag.isEmpty();
}
-
+
public Iterator entries(CollectionPersister persister) {
return bag.iterator();
}
@@ -93,8 +93,8 @@
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Collection) snapshot ).isEmpty();
}
-
- private int countOccurrences(Object element, List list, Type elementType, EntityMode entityMode)
+
+ private int countOccurrences(Object element, List list, Type elementType, EntityMode entityMode)
throws HibernateException {
Iterator iter = list.iterator();
int result=0;
@@ -208,7 +208,7 @@
return true;
}
}
-
+
public boolean isRowUpdatePossible() {
return false;
}
@@ -237,8 +237,8 @@
*/
public boolean contains(Object object) {
Boolean exists = readElementExistence(object);
- return exists==null ?
- bag.contains(object) :
+ return exists==null ?
+ bag.contains(object) :
exists.booleanValue();
}
@@ -284,8 +284,14 @@
* @see java.util.Collection#remove(Object)
*/
public boolean remove(Object o) {
- write();
- return bag.remove(o);
+ initialize( true );
+ if ( bag.remove( o ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -319,8 +325,14 @@
*/
public boolean removeAll(Collection c) {
if ( c.size()>0 ) {
- write();
- return bag.removeAll(c);
+ initialize( true );
+ if ( bag.removeAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else {
return false;
@@ -331,8 +343,14 @@
* @see java.util.Collection#retainAll(Collection)
*/
public boolean retainAll(Collection c) {
- write();
- return bag.retainAll(c);
+ initialize( true );
+ if ( bag.retainAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -343,8 +361,11 @@
queueOperation( new Clear() );
}
else {
- write();
- bag.clear();
+ initialize( true );
+ if ( ! bag.isEmpty() ) {
+ bag.clear();
+ dirty();
+ }
}
}
@@ -509,7 +530,7 @@
final class SimpleAdd implements DelayedOperation {
private Object value;
-
+
public SimpleAdd(Object value) {
this.value = value;
}
Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -76,11 +76,11 @@
public Object getIdentifier(Object entry, int i) {
return identifiers.get( new Integer(i) );
}
-
+
public boolean isWrapper(Object collection) {
return values==collection;
}
-
+
public boolean add(Object o) {
write();
values.add(o);
@@ -88,9 +88,12 @@
}
public void clear() {
- write();
- values.clear();
- identifiers.clear();
+ initialize( true );
+ if ( ! values.isEmpty() || ! identifiers.isEmpty() ) {
+ values.clear();
+ identifiers.clear();
+ dirty();
+ }
}
public boolean contains(Object o) {
@@ -113,11 +116,12 @@
}
public boolean remove(Object o) {
- write();
+ initialize( true );
int index = values.indexOf(o);
if (index>=0) {
beforeRemove(index);
values.remove(index);
+ dirty();
return true;
}
else {
@@ -126,9 +130,7 @@
}
public boolean removeAll(Collection c) {
- if ( c.size()>0 ) {
- //write();
- //return values.removeAll(c);
+ if ( c.size() > 0 ) {
boolean result = false;
Iterator iter = c.iterator();
while ( iter.hasNext() ) {
@@ -142,8 +144,14 @@
}
public boolean retainAll(Collection c) {
- write();
- return values.retainAll(c);
+ initialize( true );
+ if ( values.retainAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
public int size() {
@@ -206,7 +214,7 @@
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Map) snapshot ).isEmpty();
}
-
+
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
Map snap = (Map) getSnapshot();
List deletes = new ArrayList( snap.keySet() );
@@ -267,9 +275,9 @@
public Serializable getSnapshot(CollectionPersister persister)
throws HibernateException {
-
+
EntityMode entityMode = getSession().getEntityMode();
-
+
HashMap map = new HashMap( values.size() );
Iterator iter = values.iterator();
int i=0;
@@ -308,11 +316,11 @@
}
public boolean addAll(int index, Collection c) {
- if ( c.size()>0 ) {
- //write();
- //return values.addAll(index, c);
+ if ( c.size() > 0 ) {
Iterator iter = c.iterator();
- while ( iter.hasNext() ) add( index++, iter.next() );
+ while ( iter.hasNext() ) {
+ add( index++, iter.next() );
+ }
return true;
}
else {
Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -29,9 +29,9 @@
protected List list;
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
-
+
EntityMode entityMode = getSession().getEntityMode();
-
+
ArrayList clonedList = new ArrayList( list.size() );
Iterator iter = list.iterator();
while ( iter.hasNext() ) {
@@ -62,7 +62,7 @@
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Collection) snapshot ).isEmpty();
}
-
+
public PersistentList(SessionImplementor session) {
super(session);
}
@@ -73,7 +73,7 @@
setInitialized();
setDirectlyAccessible(true);
}
-
+
public void beforeInitialize(CollectionPersister persister, int anticipatedSize) {
this.list = ( List ) persister.getCollectionType().instantiate( anticipatedSize );
}
@@ -81,7 +81,7 @@
public boolean isWrapper(Object collection) {
return list==collection;
}
-
+
public PersistentList() {} //needed for SOAP libraries, etc
/**
@@ -103,8 +103,8 @@
*/
public boolean contains(Object object) {
Boolean exists = readElementExistence(object);
- return exists==null ?
- list.contains(object) :
+ return exists==null ?
+ list.contains(object) :
exists.booleanValue();
}
@@ -150,11 +150,16 @@
* @see java.util.List#remove(Object)
*/
public boolean remove(Object value) {
- Boolean exists = isPutQueueEnabled() ?
- readElementExistence(value) : null;
- if ( exists==null ) {
- write();
- return list.remove(value);
+ Boolean exists = isPutQueueEnabled() ? readElementExistence(value) : null;
+ if ( exists == null ) {
+ initialize( true );
+ if ( list.remove( value ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else if ( exists.booleanValue() ) {
queueOperation( new SimpleRemove(value) );
@@ -177,7 +182,9 @@
* @see java.util.List#addAll(Collection)
*/
public boolean addAll(Collection values) {
- if ( values.size()==0 ) return false;
+ if ( values.size()==0 ) {
+ return false;
+ }
if ( !isOperationQueueEnabled() ) {
write();
return list.addAll(values);
@@ -185,7 +192,7 @@
else {
Iterator iter = values.iterator();
while ( iter.hasNext() ) {
- queueOperation( new SimpleAdd( iter.next() ) );
+ queueOperation( new SimpleAdd( iter.next() ) );
}
return values.size()>0;
}
@@ -209,8 +216,14 @@
*/
public boolean removeAll(Collection coll) {
if ( coll.size()>0 ) {
- write();
- return list.removeAll(coll);
+ initialize( true );
+ if ( list.removeAll( coll ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else {
return false;
@@ -221,8 +234,14 @@
* @see java.util.List#retainAll(Collection)
*/
public boolean retainAll(Collection coll) {
- write();
- return list.retainAll(coll);
+ initialize( true );
+ if ( list.retainAll( coll ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -233,8 +252,11 @@
queueOperation( new Clear() );
}
else {
- write();
- list.clear();
+ initialize( true );
+ if ( ! list.isEmpty() ) {
+ list.clear();
+ dirty();
+ }
}
}
@@ -256,8 +278,7 @@
if (index<0) {
throw new ArrayIndexOutOfBoundsException("negative index");
}
- Object old = isPutQueueEnabled() ?
- readElementByIndex( new Integer(index) ) : UNKNOWN;
+ Object old = isPutQueueEnabled() ? readElementByIndex( new Integer(index) ) : UNKNOWN;
if ( old==UNKNOWN ) {
write();
return list.set(index, value);
@@ -352,16 +373,16 @@
return list.toString();
}
- public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
+ public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
throws HibernateException, SQLException {
Object element = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() ) ;
int index = ( (Integer) persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() ) ).intValue();
-
+
//pad with nulls from the current last element up to the new index
for ( int i = list.size(); i<=index; i++) {
list.add(i, null);
}
-
+
list.set(index, element);
return element;
}
@@ -420,7 +441,7 @@
public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException {
final List sn = (List) getSnapshot();
- return i<sn.size() && sn.get(i)!=null && list.get(i)!=null &&
+ return i<sn.size() && sn.get(i)!=null && list.get(i)!=null &&
elemType.isDirty( list.get(i), sn.get(i), getSession() );
}
@@ -450,7 +471,7 @@
public boolean entryExists(Object entry, int i) {
return entry!=null;
}
-
+
final class Clear implements DelayedOperation {
public void operate() {
list.clear();
@@ -465,7 +486,7 @@
final class SimpleAdd implements DelayedOperation {
private Object value;
-
+
public SimpleAdd(Object value) {
this.value = value;
}
@@ -483,7 +504,7 @@
final class Add implements DelayedOperation {
private int index;
private Object value;
-
+
public Add(int index, Object value) {
this.index = index;
this.value = value;
@@ -503,7 +524,7 @@
private int index;
private Object value;
private Object old;
-
+
public Set(int index, Object value, Object old) {
this.index = index;
this.value = value;
@@ -523,7 +544,7 @@
final class Remove implements DelayedOperation {
private int index;
private Object old;
-
+
public Remove(int index, Object old) {
this.index = index;
this.old = old;
@@ -541,7 +562,7 @@
final class SimpleRemove implements DelayedOperation {
private Object value;
-
+
public SimpleRemove(Object value) {
this.value = value;
}
Modified: trunk/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -2,11 +2,15 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+
+import org.hibernate.test.collection.bag.PersistentBagTest;
+import org.hibernate.test.collection.idbag.PersistentIdBagTest;
+import org.hibernate.test.collection.list.PersistentListTest;
import org.hibernate.test.collection.map.PersistentMapTest;
import org.hibernate.test.collection.set.PersistentSetTest;
/**
- * todo: describe CollectionSuite
+ * Suite of collection (i.e. PersistentCollection) related tests
*
* @author Steve Ebersole
*/
@@ -15,6 +19,9 @@
public static Test suite() {
TestSuite suite = new TestSuite( "Collection-related tests" );
suite.addTest( CollectionTest.suite() );
+ suite.addTest( PersistentBagTest.suite() );
+ suite.addTest( PersistentIdBagTest.suite() );
+ suite.addTest( PersistentListTest.suite() );
suite.addTest( PersistentMapTest.suite() );
suite.addTest( PersistentSetTest.suite() );
return suite;
Added: trunk/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,46 @@
+package org.hibernate.test.collection.bag;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class BagOwner {
+ private String name;
+ private BagOwner parent;
+ private List children = new ArrayList();
+
+ public BagOwner() {
+ }
+
+ public BagOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public BagOwner getParent() {
+ return parent;
+ }
+
+ public void setParent(BagOwner parent) {
+ this.parent = parent;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<!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.collection.bag">
+
+ <class name="BagOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <many-to-one name="parent" class="BagOwner" cascade="none" />
+
+ <bag name="children" inverse="true" cascade="all">
+ <key column="PARENT" />
+ <one-to-many class="BagOwner" />
+ </bag>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,71 @@
+package org.hibernate.test.collection.bag;
+
+import java.util.HashSet;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentBag;
+
+/**
+ * Tests related to operations on a PersistentBag.
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentBagTest extends TestCase {
+ public PersistentBagTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/bag/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentBagTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ BagOwner parent = new BagOwner( "root" );
+ BagOwner child = new BagOwner( "c1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ BagOwner otherChild = new BagOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentBag...
+ PersistentBag children = ( PersistentBag ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,37 @@
+package org.hibernate.test.collection.idbag;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class IdbagOwner {
+ private String name;
+ private List children = new ArrayList();
+
+ public IdbagOwner() {
+ }
+
+ public IdbagOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!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.collection.idbag">
+
+ <class name="IdbagOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <idbag name="children" cascade="all" table="idbag_owner_children">
+ <collection-id column="CHILD" type="long">
+ <generator class="increment"/>
+ </collection-id>
+ <key column="PARENT_FK" />
+ <many-to-many column="CHILD_FK" class="IdbagOwner" />
+ </idbag>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,69 @@
+package org.hibernate.test.collection.idbag;
+
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentIdentifierBag;
+
+/**
+ * Tests related to operations on a PersistentIdentifierBag
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentIdBagTest extends TestCase {
+ public PersistentIdBagTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/idbag/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentIdBagTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ IdbagOwner parent = new IdbagOwner( "root" );
+ IdbagOwner child = new IdbagOwner( "c1" );
+ parent.getChildren().add( child );
+ IdbagOwner otherChild = new IdbagOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentBag...
+ PersistentIdentifierBag children = ( PersistentIdentifierBag ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,46 @@
+package org.hibernate.test.collection.list;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ListOwner {
+ private String name;
+ private ListOwner parent;
+ private List children = new ArrayList();
+
+ public ListOwner() {
+ }
+
+ public ListOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ListOwner getParent() {
+ return parent;
+ }
+
+ public void setParent(ListOwner parent) {
+ this.parent = parent;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!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.collection.list">
+
+ <class name="ListOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <many-to-one name="parent" class="ListOwner" cascade="none" />
+
+ <list name="children" inverse="true" cascade="all">
+ <key column="PARENT" />
+ <list-index column="LIST_INDEX"/>
+ <one-to-many class="ListOwner" />
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java 2006-11-06 18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java 2006-11-06 21:56:38 UTC (rev 10738)
@@ -0,0 +1,70 @@
+package org.hibernate.test.collection.list;
+
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentList;
+
+/**
+ * Tests related to operations on a PersistentList
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentListTest extends TestCase {
+ public PersistentListTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/list/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentListTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ ListOwner parent = new ListOwner( "root" );
+ ListOwner child = new ListOwner( "c1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ ListOwner otherChild = new ListOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentList...
+ PersistentList children = ( PersistentList ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
18 years, 2 months
Hibernate SVN: r10737 - branches/Branch_3_2/Hibernate3/src/org/hibernate
by hibernate-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2006-11-06 13:09:47 -0500 (Mon, 06 Nov 2006)
New Revision: 10737
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java
Log:
Fixed Javadoc
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java 2006-11-06 18:09:20 UTC (rev 10736)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java 2006-11-06 18:09:47 UTC (rev 10737)
@@ -614,7 +614,7 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
- * with the session, return that instance. This method never returns an unitialized instance.)
+ * with the session, return that instance. This method never returns an uninitialized instance.)
*
* @param clazz a persistent class
* @param id an identifier
@@ -626,7 +626,7 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
- * with the session, return that instance. This method never returns an unitialized instance.)
+ * with the session, return that instance. This method never returns an uninitialized instance.)
* Obtain the specified lock mode if the instance exists.
*
* @param clazz a persistent class
@@ -640,7 +640,7 @@
/**
* Return the persistent instance of the given named entity with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
- * with the session, return that instance. This method never returns an unitialized instance.)
+ * with the session, return that instance. This method never returns an uninitialized instance.)
*
* @param entityName the entity name
* @param id an identifier
@@ -652,7 +652,7 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
- * with the session, return that instance. This method never returns an unitialized instance.)
+ * with the session, return that instance. This method never returns an uninitialized instance.)
* Obtain the specified lock mode if the instance exists.
*
* @param entityName the entity name
18 years, 2 months
Hibernate SVN: r10736 - trunk/Hibernate3/src/org/hibernate
by hibernate-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2006-11-06 13:09:20 -0500 (Mon, 06 Nov 2006)
New Revision: 10736
Modified:
trunk/Hibernate3/src/org/hibernate/Session.java
Log:
Fixed Javadoc
Modified: trunk/Hibernate3/src/org/hibernate/Session.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/Session.java 2006-11-06 18:07:45 UTC (rev 10735)
+++ trunk/Hibernate3/src/org/hibernate/Session.java 2006-11-06 18:09:20 UTC (rev 10736)
@@ -614,7 +614,7 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
- * with the session, return that instance. This method never returns an unitialized instance.)
+ * with the session, return that instance. This method never returns an uninitialized instance.)
* Obtain the specified lock mode if the instance exists.
*
* @param clazz a persistent class
@@ -627,7 +627,7 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
- * with the session, return that instance. This method never returns an unitialized instance.)
+ * with the session, return that instance. This method never returns an uninitialized instance.)
* Obtain the specified lock mode if the instance exists.
*
* @param clazz a persistent class
@@ -641,7 +641,7 @@
/**
* Return the persistent instance of the given named entity with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
- * with the session, return that instance. This method never returns an unitialized instance.)
+ * with the session, return that instance. This method never returns an uninitialized instance.)
*
* @param entityName the entity name
* @param id an identifier
@@ -653,7 +653,7 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. (If the instance is already associated
- * with the session, return that instance. This method never returns an unitialized instance.)
+ * with the session, return that instance. This method never returns an uninitialized instance.)
* Obtain the specified lock mode if the instance exists.
*
* @param entityName the entity name
18 years, 2 months
Hibernate SVN: r10735 - trunk/Hibernate3/src/org/hibernate
by hibernate-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2006-11-06 13:07:45 -0500 (Mon, 06 Nov 2006)
New Revision: 10735
Modified:
trunk/Hibernate3/src/org/hibernate/Session.java
Log:
Fixed Javadoc
Modified: trunk/Hibernate3/src/org/hibernate/Session.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/Session.java 2006-11-06 18:07:22 UTC (rev 10734)
+++ trunk/Hibernate3/src/org/hibernate/Session.java 2006-11-06 18:07:45 UTC (rev 10735)
@@ -236,7 +236,8 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * assuming that the instance exists.
+ * assuming that the instance exists. This method might return a proxied instance that
+ * is initialized on-demand, when a non-identifier method is accessed.
* <br><br>
* You should not use this method to determine if an instance exists (use <tt>get()</tt>
* instead). Use this only to retrieve an instance that you assume exists, where non-existence
@@ -251,7 +252,8 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * assuming that the instance exists.
+ * assuming that the instance exists. This method might return a proxied instance that
+ * is initialized on-demand, when a non-identifier method is accessed.
* <br><br>
* You should not use this method to determine if an instance exists (use <tt>get()</tt>
* instead). Use this only to retrieve an instance that you assume exists, where non-existence
@@ -324,7 +326,7 @@
* with <tt>cascade="save-update"</tt>.
*
* @see Session#save(java.lang.Object)
- * @see Session#update(Object object, Serializable id)
+ * @see Session#update(Object object)
* @param object a transient or detached instance containing new or updated state
* @throws HibernateException
*/
@@ -338,7 +340,7 @@
* with <tt>cascade="save-update"</tt>.
*
* @see Session#save(java.lang.Object)
- * @see Session#update(Object object, Serializable id)
+ * @see Session#update(Object object)
* @param object a transient or detached instance containing new or updated state
* @throws HibernateException
*/
@@ -611,8 +613,9 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * or null if there is no such persistent instance. (If the instance, or a proxy for the
- * instance, is already associated with the session, return that instance or proxy.)
+ * or null if there is no such persistent instance. (If the instance is already associated
+ * with the session, return that instance. This method never returns an unitialized instance.)
+ * Obtain the specified lock mode if the instance exists.
*
* @param clazz a persistent class
* @param id an identifier
@@ -623,8 +626,9 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * or null if there is no such persistent instance. Obtain the specified lock mode
- * if the instance exists.
+ * or null if there is no such persistent instance. (If the instance is already associated
+ * with the session, return that instance. This method never returns an unitialized instance.)
+ * Obtain the specified lock mode if the instance exists.
*
* @param clazz a persistent class
* @param id an identifier
@@ -636,8 +640,8 @@
/**
* Return the persistent instance of the given named entity with the given identifier,
- * or null if there is no such persistent instance. (If the instance, or a proxy for the
- * instance, is already associated with the session, return that instance or proxy.)
+ * or null if there is no such persistent instance. (If the instance is already associated
+ * with the session, return that instance. This method never returns an unitialized instance.)
*
* @param entityName the entity name
* @param id an identifier
@@ -648,8 +652,9 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * or null if there is no such persistent instance. Obtain the specified lock mode
- * if the instance exists.
+ * or null if there is no such persistent instance. (If the instance is already associated
+ * with the session, return that instance. This method never returns an unitialized instance.)
+ * Obtain the specified lock mode if the instance exists.
*
* @param entityName the entity name
* @param id an identifier
18 years, 2 months
Hibernate SVN: r10734 - branches/Branch_3_2/Hibernate3/src/org/hibernate
by hibernate-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2006-11-06 13:07:22 -0500 (Mon, 06 Nov 2006)
New Revision: 10734
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java
Log:
Fixed Javadoc
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java 2006-11-06 17:59:29 UTC (rev 10733)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/Session.java 2006-11-06 18:07:22 UTC (rev 10734)
@@ -236,7 +236,8 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * assuming that the instance exists.
+ * assuming that the instance exists. This method might return a proxied instance that
+ * is initialized on-demand, when a non-identifier method is accessed.
* <br><br>
* You should not use this method to determine if an instance exists (use <tt>get()</tt>
* instead). Use this only to retrieve an instance that you assume exists, where non-existence
@@ -251,7 +252,8 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * assuming that the instance exists.
+ * assuming that the instance exists. This method might return a proxied instance that
+ * is initialized on-demand, when a non-identifier method is accessed.
* <br><br>
* You should not use this method to determine if an instance exists (use <tt>get()</tt>
* instead). Use this only to retrieve an instance that you assume exists, where non-existence
@@ -324,7 +326,7 @@
* with <tt>cascade="save-update"</tt>.
*
* @see Session#save(java.lang.Object)
- * @see Session#update(Object object, Serializable id)
+ * @see Session#update(Object object)
* @param object a transient or detached instance containing new or updated state
* @throws HibernateException
*/
@@ -338,7 +340,7 @@
* with <tt>cascade="save-update"</tt>.
*
* @see Session#save(java.lang.Object)
- * @see Session#update(Object object, Serializable id)
+ * @see Session#update(Object object)
* @param object a transient or detached instance containing new or updated state
* @throws HibernateException
*/
@@ -611,8 +613,8 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * or null if there is no such persistent instance. (If the instance, or a proxy for the
- * instance, is already associated with the session, return that instance or proxy.)
+ * or null if there is no such persistent instance. (If the instance is already associated
+ * with the session, return that instance. This method never returns an unitialized instance.)
*
* @param clazz a persistent class
* @param id an identifier
@@ -623,8 +625,9 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * or null if there is no such persistent instance. Obtain the specified lock mode
- * if the instance exists.
+ * or null if there is no such persistent instance. (If the instance is already associated
+ * with the session, return that instance. This method never returns an unitialized instance.)
+ * Obtain the specified lock mode if the instance exists.
*
* @param clazz a persistent class
* @param id an identifier
@@ -636,8 +639,8 @@
/**
* Return the persistent instance of the given named entity with the given identifier,
- * or null if there is no such persistent instance. (If the instance, or a proxy for the
- * instance, is already associated with the session, return that instance or proxy.)
+ * or null if there is no such persistent instance. (If the instance is already associated
+ * with the session, return that instance. This method never returns an unitialized instance.)
*
* @param entityName the entity name
* @param id an identifier
@@ -648,8 +651,9 @@
/**
* Return the persistent instance of the given entity class with the given identifier,
- * or null if there is no such persistent instance. Obtain the specified lock mode
- * if the instance exists.
+ * or null if there is no such persistent instance. (If the instance is already associated
+ * with the session, return that instance. This method never returns an unitialized instance.)
+ * Obtain the specified lock mode if the instance exists.
*
* @param entityName the entity name
* @param id an identifier
18 years, 2 months
Hibernate SVN: r10733 - in trunk/Hibernate3/test/org/hibernate/test/jpa: . ql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-06 12:59:29 -0500 (Mon, 06 Nov 2006)
New Revision: 10733
Added:
trunk/Hibernate3/test/org/hibernate/test/jpa/MyEntity.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/jpa/MyEntity.java
trunk/Hibernate3/test/org/hibernate/test/jpa/MySubclassEntity.java
Modified:
trunk/Hibernate3/test/org/hibernate/test/jpa/AbstractJPATest.java
trunk/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java
Log:
testing user assertion that JPA case insensitivity support breaks class-name -> discriminator value resolution
Modified: trunk/Hibernate3/test/org/hibernate/test/jpa/AbstractJPATest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/AbstractJPATest.java 2006-11-06 17:58:49 UTC (rev 10732)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/AbstractJPATest.java 2006-11-06 17:59:29 UTC (rev 10733)
@@ -18,7 +18,7 @@
import java.io.Serializable;
/**
- * todo: describe AbstractJPATest
+ * An abstract test for all JPA spec related tests.
*
* @author Steve Ebersole
*/
@@ -28,7 +28,7 @@
}
protected String[] getMappings() {
- return new String[] { "jpa/Part.hbm.xml", "jpa/Item.hbm.xml" };
+ return new String[] { "jpa/Part.hbm.xml", "jpa/Item.hbm.xml", "jpa/MyEntity.hbm.xml" };
}
protected void configure(Configuration cfg) {
Added: trunk/Hibernate3/test/org/hibernate/test/jpa/MyEntity.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/MyEntity.hbm.xml 2006-11-06 17:58:49 UTC (rev 10732)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/MyEntity.hbm.xml 2006-11-06 17:59:29 UTC (rev 10733)
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<hibernate-mapping package="org.hibernate.test.jpa">
+
+ <class name="MyEntity" table="JPA_MYENTITY" discriminator-value="E">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <discriminator column="TYPE" />
+ <property name="name" type="string"/>
+ <many-to-one name="other" class="MyEntity" />
+ <subclass name="MySubclassEntity" discriminator-value="S">
+ <property name="someSubProperty"/>
+ </subclass>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/jpa/MyEntity.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/MyEntity.java 2006-11-06 17:58:49 UTC (rev 10732)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/MyEntity.java 2006-11-06 17:59:29 UTC (rev 10733)
@@ -0,0 +1,36 @@
+package org.hibernate.test.jpa;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class MyEntity {
+ private Long id;
+ private String name;
+ private MyEntity other;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public MyEntity getOther() {
+ return other;
+ }
+
+ public void setOther(MyEntity other) {
+ this.other = other;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/jpa/MySubclassEntity.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/MySubclassEntity.java 2006-11-06 17:58:49 UTC (rev 10732)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/MySubclassEntity.java 2006-11-06 17:59:29 UTC (rev 10733)
@@ -0,0 +1,18 @@
+package org.hibernate.test.jpa;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class MySubclassEntity extends MyEntity {
+ private String someSubProperty;
+
+ public String getSomeSubProperty() {
+ return someSubProperty;
+ }
+
+ public void setSomeSubProperty(String someSubProperty) {
+ this.someSubProperty = someSubProperty;
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java 2006-11-06 17:58:49 UTC (rev 10732)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java 2006-11-06 17:59:29 UTC (rev 10733)
@@ -31,6 +31,11 @@
public void testIdentifierCaseSensitive() throws Exception {
Session s = openSession( );
+ // a control test (a user reported that the JPA 'case insensitivity' support
+ // caused problems with the "discriminator resolution" code; unable to reproduce)...
+ s.createQuery( "from MyEntity e where e.class = MySubclassEntity" );
+ s.createQuery( "from MyEntity e where e.other.class = MySubclassEntity" );
+
s.createQuery( "select object(I) from Item i").list();
s.close();
}
18 years, 2 months
Hibernate SVN: r10732 - in branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa: . ql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-06 12:58:49 -0500 (Mon, 06 Nov 2006)
New Revision: 10732
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MyEntity.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MyEntity.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MySubclassEntity.java
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/AbstractJPATest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java
Log:
testing user assertion that JPA case insensitivity support breaks class-name -> discriminator value resolution
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/AbstractJPATest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/AbstractJPATest.java 2006-11-06 17:50:54 UTC (rev 10731)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/AbstractJPATest.java 2006-11-06 17:58:49 UTC (rev 10732)
@@ -18,7 +18,7 @@
import java.io.Serializable;
/**
- * todo: describe AbstractJPATest
+ * An abstract test for all JPA spec related tests.
*
* @author Steve Ebersole
*/
@@ -28,7 +28,7 @@
}
protected String[] getMappings() {
- return new String[] { "jpa/Part.hbm.xml", "jpa/Item.hbm.xml" };
+ return new String[] { "jpa/Part.hbm.xml", "jpa/Item.hbm.xml", "jpa/MyEntity.hbm.xml" };
}
protected void configure(Configuration cfg) {
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MyEntity.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MyEntity.hbm.xml 2006-11-06 17:50:54 UTC (rev 10731)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MyEntity.hbm.xml 2006-11-06 17:58:49 UTC (rev 10732)
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<hibernate-mapping package="org.hibernate.test.jpa">
+
+ <class name="MyEntity" table="JPA_MYENTITY" discriminator-value="E">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <discriminator column="TYPE" />
+ <property name="name" type="string"/>
+ <many-to-one name="other" class="MyEntity" />
+ <subclass name="MySubclassEntity" discriminator-value="S">
+ <property name="someSubProperty"/>
+ </subclass>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MyEntity.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MyEntity.java 2006-11-06 17:50:54 UTC (rev 10731)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MyEntity.java 2006-11-06 17:58:49 UTC (rev 10732)
@@ -0,0 +1,36 @@
+package org.hibernate.test.jpa;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class MyEntity {
+ private Long id;
+ private String name;
+ private MyEntity other;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public MyEntity getOther() {
+ return other;
+ }
+
+ public void setOther(MyEntity other) {
+ this.other = other;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MySubclassEntity.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MySubclassEntity.java 2006-11-06 17:50:54 UTC (rev 10731)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/MySubclassEntity.java 2006-11-06 17:58:49 UTC (rev 10732)
@@ -0,0 +1,18 @@
+package org.hibernate.test.jpa;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class MySubclassEntity extends MyEntity {
+ private String someSubProperty;
+
+ public String getSomeSubProperty() {
+ return someSubProperty;
+ }
+
+ public void setSomeSubProperty(String someSubProperty) {
+ this.someSubProperty = someSubProperty;
+ }
+}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java 2006-11-06 17:50:54 UTC (rev 10731)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java 2006-11-06 17:58:49 UTC (rev 10732)
@@ -2,7 +2,6 @@
import org.hibernate.test.jpa.AbstractJPATest;
import org.hibernate.Session;
-import org.hibernate.hql.ast.QuerySyntaxException;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -31,6 +30,11 @@
public void testIdentifierCaseSensitive() throws Exception {
Session s = openSession( );
+ // a control test (a user reported that the JPA 'case insensitivity' support
+ // caused problems with the "discriminator resolution" code; unable to reproduce)...
+ s.createQuery( "from MyEntity e where e.class = MySubclassEntity" );
+ s.createQuery( "from MyEntity e where e.other.class = MySubclassEntity" );
+
s.createQuery( "select object(I) from Item i").list();
s.close();
}
18 years, 2 months