From f08c44025d221295653a3b12eb20bd41a4f9606e Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Wed, 3 May 2006 12:33:26 +0000 Subject: [PATCH] Ensure initialization of the Hibernate association bags - If uninitialized (e.g. by a size() call), then the new assocations added are queued for addition - These then become duplicated within the session (not the DB) and appear as duplicate associations during integrity checking Fixed test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2741 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/domain/hibernate/ChildAssocImpl.java | 5 +++++ .../alfresco/repo/domain/hibernate/HibernateNodeTest.java | 1 + .../org/alfresco/repo/domain/hibernate/NodeAssocImpl.java | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/source/java/org/alfresco/repo/domain/hibernate/ChildAssocImpl.java b/source/java/org/alfresco/repo/domain/hibernate/ChildAssocImpl.java index 25c86778af..9b3c31bfa0 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/ChildAssocImpl.java +++ b/source/java/org/alfresco/repo/domain/hibernate/ChildAssocImpl.java @@ -46,6 +46,11 @@ public class ChildAssocImpl implements ChildAssoc // add the forward associations this.setParent(parentNode); this.setChild(childNode); + // Force initialization of the inverse collections + // so that we don't queue additions to them. + // This can go if we move to set-based collections + parentNode.getChildAssocs().size(); + childNode.getParentAssocs().size(); // add the inverse associations parentNode.getChildAssocs().add(this); childNode.getParentAssocs().add(this); diff --git a/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java b/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java index 86b8021c84..f291218312 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java +++ b/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java @@ -263,6 +263,7 @@ public class HibernateNodeTest extends BaseSpringTest // make a content node Node contentNode = new NodeImpl(); contentNode.setStore(store); + contentNode.setUuid(GUID.generate()); contentNode.setTypeQName(ContentModel.TYPE_CONTENT); Serializable contentNodeId = getSession().save(contentNode); diff --git a/source/java/org/alfresco/repo/domain/hibernate/NodeAssocImpl.java b/source/java/org/alfresco/repo/domain/hibernate/NodeAssocImpl.java index 7535736427..b69f1a5376 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/NodeAssocImpl.java +++ b/source/java/org/alfresco/repo/domain/hibernate/NodeAssocImpl.java @@ -44,6 +44,11 @@ public class NodeAssocImpl implements NodeAssoc // add the forward associations this.setTarget(targetNode); this.setSource(sourceNode); + // Force initialization of the inverse collections + // so that we don't queue additions to them. + // This can go if we move to set-based collections + sourceNode.getSourceNodeAssocs().size(); + targetNode.getTargetNodeAssocs().size(); // add the inverse associations sourceNode.getTargetNodeAssocs().add(this); targetNode.getSourceNodeAssocs().add(this);