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.  [ 1 post ] 
Author Message
 Post subject: Lock(obj, LockMode.None) not working when there is collectio
PostPosted: Mon Aug 28, 2006 1:00 pm 
Beginner
Beginner

Joined: Wed Dec 28, 2005 3:14 pm
Posts: 29
A Jira issue has been created on this bug:
http://jira.nhibernate.org/browse/NH-704

As we all know, there are two means of re-attach a detached object: 1) sess.Update(obj) and 2) sess.Lock(c, LockMode.None);
In 1.2.0 Alpha1, the second meanning does not work. If there is a collection in the entity, Lock() will throw an exception (but now error was found in the log file).
Here are the code and the mapping file, which can also be found in the attachment.

Hibernate version: 1.2.0 alpha1

Mapping documents:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo" assembly="NHSessTest" default-lazy="false">
  <class name="NHSessTest.Cat" >
    <id name="Id" type="Int32" unsaved-value="0" >
      <generator class="identity" />
    </id>
   
        <bag name="Children" cascade="all-delete-orphan" lazy="true">
          <key column="parentId" />
      <one-to-many class="NHSessTest.Cat" />
    </bag>
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
  public class Cat{
        private int id;
        private IList children = new ArrayList();
        //Note: I initialized the collection here, if removed, Lock will work.

        public int Id{
            get { return id; }
            set { id = value; }
        }

        public IList Children {
            get { return children; }
            set { children = value; }
        }
    }



Code:


  Cat c = new Cat();
            sess.Save(c);
            sess.Clear();
             
            sess.Update(c); //Update() works fine
             
            sess.Clear();
           
            sess.Lock(c, LockMode.None); //Exception throw here

           


Full stack trace of any exception that occurs:
NHibernate.HibernateException: reassociated object has dirty collection reference

at NHibernate.Impl.OnLockVisitor.ProcessCollection(Object collection, CollectionType type) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\OnLockVisitor.cs:line 58
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\AbstractVisitor.cs:line 57
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\AbstractVisitor.cs:line 30
at NHibernate.Impl.AbstractVisitor.Process(Object obj, IEntityPersister persister) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\AbstractVisitor.cs:line 82
at NHibernate.Impl.SessionImpl.Reassociate(Object obj, Object id, IEntityPersister persister) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1983
at NHibernate.Impl.SessionImpl.Lock(Object obj, LockMode lockMode) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 2025
at NHSessTest.Tests.Work.ReAttachTest.ReAttachCatTest() in ReAttachTest.cs:line 23

Name and version of the database you are using:
SqlServer 2000
[/code]


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

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.