-->
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.  [ 3 posts ] 
Author Message
 Post subject: Reassociated object has dirty collection
PostPosted: Wed Oct 25, 2006 4:54 am 
Beginner
Beginner

Joined: Wed May 03, 2006 5:10 am
Posts: 32
Location: Monopoli - Italy
I have an Order class with two one-to-many relations with lazy = "true".

I load an order, then I have:

//client code
order.Details1.Add(detail); //now the collection is dirty

order.Details2.Count --> throws HibernateException("reassociated object has dirty collection")

This happens when the LazyLoad method tries to attach the second collection to the order object.
The property Snapshot.Dirty after adding the detail is set to true.

Code:
//extract of lazy load method...
if (!NHibernateUtil.IsInitialized(nativeColl))
{
   openSession();
   _session.Lock(item, LockMode.None);
   NHibernateUtil.Initialize(nativeColl);
   closeSession();
}



I need a workaround to solve this problem, because this error is thrown in a wizard and I cannot save the Order before the user finish the operation.


Any idea?

Antonella

Hibernate version: 1.0.2

Full stack trace of any exception that occurs:

at NHibernate.Impl.OnLockVisitor.ProcessCollection(Object collection, PersistentCollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IClassPersister persister)
at NHibernate.Impl.SessionImpl.Reassociate(Object obj, Object id, IClassPersister persister)
at NHibernate.Impl.SessionImpl.Lock(Object obj, LockMode lockMode)
at Persistence.Repository.ReconnectSession(ItemBase item, IList nativeColl) in D:\...\BackEnd\Repository\Repository.cs:line 469


Name and version of the database you are using:
SQL SERVER 2000

_________________
Antonella


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 6:33 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 6:21 pm
Posts: 24
Location: Antwerp, Belgium
Ciao bella :-)

I'm going to repost something that Sergey posted once:

---------------------------------------------------------------------------------
Object states:
- transient = does not exist in the database (i.e. not yet saved or already deleted) => is not attached to a session (only objects that exist in the database may be attached to a session)
- persistent = exists in the database, is attached to an open session
- detached = exists in the database, is not attached to an open session

Methods:
- Lock(object, LockMode.None) - reattach a definitely unmodified detached object to a session (detached => persistent)
- Update(object) - reattach a possibly modified detached object to a session (detached => persistent)
- Save(object) - make transient object persistent (transient => persistent)
- SaveOrUpdate(object) - either save or update depending on the object state (any state => persistent)

- SaveOrUpdateCopy(object) - don't change the state of the object itself, instead load a persistent copy in the session and merge the changes onto that (this operation is called merge in Hibernate 3).
--------------------------------------------------------------------------------

So basically, if you think your object might have changed since
it was loaded from the previous (now discarded) session use
.Update() instead of .Lock()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 4:22 am 
Beginner
Beginner

Joined: Wed May 03, 2006 5:10 am
Posts: 32
Location: Monopoli - Italy
Thanks for your help, I solved the problem!!!

I already tried with Update to solve the problem, but I put it in the catch after wrapping the "Reassociated object has dirty collection" exception... but it didn't work.

After your post I used Update instead of Lock and now it's working fine!

Thank you so much

_________________
Antonella


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.