-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: why "reassociated object has dirty collection reference
PostPosted: Thu Sep 16, 2004 1:45 pm 
Beginner
Beginner

Joined: Mon May 03, 2004 1:25 pm
Posts: 31
I have a process that creates a group of GeoGroup objects, at creation time, one of the collections, weightingTreatments, is uninitialized. The session then closes.

Later on, another process updates the GeoGroups and creates the weightingTreatments, when I try to update the geogroups i get the reassociated objects are dirty exception. The interesting thing is that the exception occurs on the other collection, the baseSamplingGeos.

The baseSamplingGeos are defined as a Set and instatiated as a TreeSet.

What am i doing wrong?



Hibernate version:3

Mapping documents:
<hibernate-mapping package="com.arbitron.currency.weight">
<class name="GeoGroup" table="SRVY_GEO_GROUP" mutable="false">
<id name="id" type="long" column="GEO_GROUP_ID">
<generator class="sequence">
<param name="sequence">wmg_seq</param>
</generator>
</id>
<property name="code" column="GEO_GROUP_CODE"/>
<property name="name" column="GEO_GROUP_NAME"/>
<many-to-one name="survey" class="com.arbitron.geodemo.Survey" column="SRVY_ID"/>
<set name="baseSamplingGeos" table="SRVY_GEO_GROUP_SMPL_GEO" lazy="true" batch-size="100">
<key column="GEO_GROUP_ID"/>
<many-to-many class="com.arbitron.geodemo.SamplingGeography" column="SMPL_GEO_GNMBR"/>
</set>
<set name="weightingTreatments" table="SRVY_GEO_GROUP_MODEL_TRTMT" lazy="true" cascade="all">
<key column="GEO_GROUP_ID"/>
<one-to-many class="WeightingTreatment"/>
</set>

</class>
<class name="WeightingTreatment" table="SRVY_GEO_GROUP_MODEL_TRTMT">
<id name="id" type="long" column="GEO_GROUP_MODEL_TRTMT_ID">
<generator class="sequence"/>
</id>
<property name="treatmentCode" column="TREATMENT_CODE"/>
<property name="intabTarget" column="INTAB_TARGET_NMBR"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
createGeoGroups() {
List geoGroupList;
Iterator marketSurveyIter;
Transaction trans = null;
try {
String qString = marketIds == null || marketIds.isEmpty() ?
QUERY_STRING : QUERY_STRING + MARKET_QUERY;
Session session = sessionFactory.openSession();

while (en.hasMoreElements()) {
marketNode = (DefaultMutableTreeNode) en.nextElement();
processMarketNode(geoGroupList, marketNode);
}
Iterator ggIter = geoGroupList.iterator();
trans = session.beginTransaction();
while (ggIter.hasNext()){
GeoGroupMarkets ggm = (GeoGroupMarkets)ggIter.next();

session.saveOrUpdate(ggm.getGeoGroup());
}
trans.commit();
session.close();
} catch (HibernateException ex) {
trans.rollback();
throw new FunctorException(ex);
}

return geoGroupList;
}


createModels(){
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
List list = (List) geoGroupFactory.create();
list = (List) CollectionUtils.collect
(list, geoGroup2Model, new ArrayList(list.size()));
Collections.reverse(list);

Stack stack = new Stack();
stack.addAll(list);
list.clear();
Model model;
MecePredicateList mpl;
Model[] splitModels;
boolean addToList = true;

while (!stack.empty()) {
addToList = true;
model = (Model) stack.pop();
for (int i=0, n = mplArray.length; i < n ; i++) {
mpl = mplArray[i];
splitModels = mpl.split(model);
if (splitModels == null) {
mpl.applyAsMarginal(model);
} else {
GeoGroup gg = ((GeoGroupMarkets)model.getUserObject()).getGeoGroup();
session.update(gg);
for (int j = splitModels.length; j >= 0; j--) {
stack.push(model);

}
i=mplArray.length;
addToList=false;
}
}
if (addToList)list.add(model);

}

this.models = list;
tx.commit();

}


Full stack trace of any exception that occurs:
org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)
at org.hibernate.event.OnLockVisitor.processCollection(OnLockVisitor.java:66)
at org.hibernate.event.AbstractVisitor.processValue(AbstractVisitor.java:76)
at org.hibernate.event.AbstractVisitor.processValues(AbstractVisitor.java:42)
at org.hibernate.event.AbstractVisitor.process(AbstractVisitor.java:101)
at org.hibernate.event.AbstractReassociateEventListener.reassociate(AbstractReassociateEventListener.java:67)
at org.hibernate.event.DefaultLockEventListener.onLock(DefaultLockEventListener.java:58)
at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:960)
at com.arbitron.currency.weight.WeightingManager.<init>(WeightingManager.java:77)
at com.arbitron.currency.weighting.ui.WeightingRunUI.getModelSet(WeightingRunUI.java:218)
at com.arbitron.currency.weighting.ui.WeightingRunUI.determine(WeightingRunUI.java:337)
at com.arbitron.currency.weighting.ui.WeightingRunUI.actionPerformed(WeightingRunUI.java:301)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


Name and version of the database you are using:Oracle91


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 1:46 pm 
Beginner
Beginner

Joined: Mon May 03, 2004 1:25 pm
Posts: 31
I forgot to add that the baseSamplingGeos are not changed at all during the creation of WeightingTreatments.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 2:54 pm 
Beginner
Beginner

Joined: Mon May 03, 2004 1:25 pm
Posts: 31
Here's the line that causes the exception:

Code:

else if ( collection instanceof PersistentCollection ) {
//yada yada
}

else {
         // brand new collection
         //TODO: or an array!! we can't lock objects with arrays now??
         throw new HibernateException("reassociated object has dirty collection reference (or an array)");
      }



does this mean that the collection needs to be initialized when the parent is saved?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 4:53 pm 
Beginner
Beginner

Joined: Mon May 03, 2004 1:25 pm
Posts: 31
Nevermind, pulled my head out my butt, got oxygen flowing back to my brain, and fixed my issue.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 15, 2005 9:20 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
For those of us still having butt-breathing problems, could you describe what the actual fix was and why it fixed it?

Thanks :-)
Cheers,
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 9:14 am 
Newbie

Joined: Tue Oct 11, 2005 4:38 pm
Posts: 7
yes, that would be nice. We have the same problem


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 9:35 am 
Newbie

Joined: Tue Oct 11, 2005 4:38 pm
Posts: 7
We found one reason, why this can happen. We had a collection mapping with the following set method in the pojo
Code:

public class pojo {

....

    private SortedSet   _users   = new TreeSet(_comparator);

----

    private final void setUsers( SortedSet users )
    {
       if ( users == null || users.isEmpty() )
          return;

       _users = users;
    }
....
}


What happens here is, that hibernate calls the setxx() with an initialized, but empty collection. This is not set so the collection stays as the constructor left it. It may be null in other cases. When re-associating, hibernate sees a collection, which has not been set by it. So it can only conclude, that someone else has called setxxx(), which makes the collection really dirty.

Rule: Only use simple set methods


Top
 Profile  
 
 Post subject: reattaching....
PostPosted: Fri Jan 06, 2006 7:20 pm 
How can I reattach a graph of Objects that came from my jsp become reassociated to my Session if I've been suggested in the javadoc to not intantiate PersistentSet?

In this case I have a HashSet and inside it half of the elements i had before sending the page to the client (browser).

Actually what i'm trying to do it use the delete-orphan to automatically delete elements that WERE in my Collection(inside a graph) once...

Cheers,


:Luiz.


Top
  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 5:06 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
i think session.lock() may help u

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject: Re: why "reassociated object has dirty collection refer
PostPosted: Thu Feb 02, 2006 4:15 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
i've came across same exception . it was solved when i changed session.lock() to session.update() to reattach the class .
hope this will help :)

duggant wrote:
I have a process that creates a group of GeoGroup objects, at creation time, one of the collections, weightingTreatments, is uninitialized. The session then closes.

Later on, another process updates the GeoGroups and creates the weightingTreatments, when I try to update the geogroups i get the reassociated objects are dirty exception. The interesting thing is that the exception occurs on the other collection, the baseSamplingGeos.

The baseSamplingGeos are defined as a Set and instatiated as a TreeSet.

What am i doing wrong?



Hibernate version:3

Mapping documents:
<hibernate-mapping package="com.arbitron.currency.weight">
<class name="GeoGroup" table="SRVY_GEO_GROUP" mutable="false">
<id name="id" type="long" column="GEO_GROUP_ID">
<generator class="sequence">
<param name="sequence">wmg_seq</param>
</generator>
</id>
<property name="code" column="GEO_GROUP_CODE"/>
<property name="name" column="GEO_GROUP_NAME"/>
<many-to-one name="survey" class="com.arbitron.geodemo.Survey" column="SRVY_ID"/>
<set name="baseSamplingGeos" table="SRVY_GEO_GROUP_SMPL_GEO" lazy="true" batch-size="100">
<key column="GEO_GROUP_ID"/>
<many-to-many class="com.arbitron.geodemo.SamplingGeography" column="SMPL_GEO_GNMBR"/>
</set>
<set name="weightingTreatments" table="SRVY_GEO_GROUP_MODEL_TRTMT" lazy="true" cascade="all">
<key column="GEO_GROUP_ID"/>
<one-to-many class="WeightingTreatment"/>
</set>

</class>
<class name="WeightingTreatment" table="SRVY_GEO_GROUP_MODEL_TRTMT">
<id name="id" type="long" column="GEO_GROUP_MODEL_TRTMT_ID">
<generator class="sequence"/>
</id>
<property name="treatmentCode" column="TREATMENT_CODE"/>
<property name="intabTarget" column="INTAB_TARGET_NMBR"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
createGeoGroups() {
List geoGroupList;
Iterator marketSurveyIter;
Transaction trans = null;
try {
String qString = marketIds == null || marketIds.isEmpty() ?
QUERY_STRING : QUERY_STRING + MARKET_QUERY;
Session session = sessionFactory.openSession();

while (en.hasMoreElements()) {
marketNode = (DefaultMutableTreeNode) en.nextElement();
processMarketNode(geoGroupList, marketNode);
}
Iterator ggIter = geoGroupList.iterator();
trans = session.beginTransaction();
while (ggIter.hasNext()){
GeoGroupMarkets ggm = (GeoGroupMarkets)ggIter.next();

session.saveOrUpdate(ggm.getGeoGroup());
}
trans.commit();
session.close();
} catch (HibernateException ex) {
trans.rollback();
throw new FunctorException(ex);
}

return geoGroupList;
}


createModels(){
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
List list = (List) geoGroupFactory.create();
list = (List) CollectionUtils.collect
(list, geoGroup2Model, new ArrayList(list.size()));
Collections.reverse(list);

Stack stack = new Stack();
stack.addAll(list);
list.clear();
Model model;
MecePredicateList mpl;
Model[] splitModels;
boolean addToList = true;

while (!stack.empty()) {
addToList = true;
model = (Model) stack.pop();
for (int i=0, n = mplArray.length; i < n ; i++) {
mpl = mplArray[i];
splitModels = mpl.split(model);
if (splitModels == null) {
mpl.applyAsMarginal(model);
} else {
GeoGroup gg = ((GeoGroupMarkets)model.getUserObject()).getGeoGroup();
session.update(gg);
for (int j = splitModels.length; j >= 0; j--) {
stack.push(model);

}
i=mplArray.length;
addToList=false;
}
}
if (addToList)list.add(model);

}

this.models = list;
tx.commit();

}


Full stack trace of any exception that occurs:
org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)
at org.hibernate.event.OnLockVisitor.processCollection(OnLockVisitor.java:66)
at org.hibernate.event.AbstractVisitor.processValue(AbstractVisitor.java:76)
at org.hibernate.event.AbstractVisitor.processValues(AbstractVisitor.java:42)
at org.hibernate.event.AbstractVisitor.process(AbstractVisitor.java:101)
at org.hibernate.event.AbstractReassociateEventListener.reassociate(AbstractReassociateEventListener.java:67)
at org.hibernate.event.DefaultLockEventListener.onLock(DefaultLockEventListener.java:58)
at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:960)
at com.arbitron.currency.weight.WeightingManager.<init>(WeightingManager.java:77)
at com.arbitron.currency.weighting.ui.WeightingRunUI.getModelSet(WeightingRunUI.java:218)
at com.arbitron.currency.weighting.ui.WeightingRunUI.determine(WeightingRunUI.java:337)
at com.arbitron.currency.weighting.ui.WeightingRunUI.actionPerformed(WeightingRunUI.java:301)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


Name and version of the database you are using:Oracle91

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.