-->
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.  [ 2 posts ] 
Author Message
 Post subject: Status 'saveOrUpdateCopy'-Bug (confirmed by Gavin)?
PostPosted: Fri Dec 03, 2004 5:50 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
Hibernate version:
2.1.7

Hi,
i have to use 'saveOrUpdateCopy' and i'm now facing the problem mentioned in this thread: http://forum.hibernate.org/viewtopic.ph ... updatecopy

Because it seems to me, that this bug wasn't fixed until now, i want to ask how the plans are to do this ... otherwise i'm forced to try solving it on my own (which propably won't be that easy ... ;-) ) ...

Well ... i hope i'm rigth with my thought that this bug wasn't fixed ... at least i'm having the problems mentioned in that thread ... if it's allready fixed, sorry! but i'm pretty sure ....

TiA
curio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 03, 2004 10:11 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
okay ...i could provide some more information now and would be glad if someone could tell me why that doesn't work with 'saveOrUpdateCopy' ...

mapping-files
Code:
<hibernate-mapping>
   <class
     name="test.hibernate.Box"
     table="box">

     <id
        name="boxID"
        column="bid"
        unsaved-value="null"
        access="field"
        type="integer">
        <generator class="native"/>
     </id>

    <version name="version" access="field" column="version" type="integer"/>

      <property
        name="boxNumber"
        column="boxNr"
        type="integer"/>
       
     <set
      name="toys"
      table="toy"
      inverse="true"
      outer-join="true"
      cascade="save-update">
      <key column="box_bid"/>
      <one-to-many class="test.hibernate.Toy"/>
    </set>
   
    <many-to-one
      name="delivery"
      column="Delivery_did"
      class="test.hibernate.Delivery"
      outer-join="true"/>
   </class>

</hibernate-mapping>


Code:
<hibernate-mapping>
   <class
     name="test.hibernate.Delivery"
     table="delivery">

     <id
        name="deliveryID"
        column="did"
        unsaved-value="null"
        access="field"
        type="integer">        
        <generator class="native"/>
     </id>

    <version name="version" access="field" column="version" type="integer"/>
   
      <property
        name="deliveryDate"
        column="delDate"
        type="date"/>
   
    <set
      name="boxes"
      table="box"
      inverse="true"
      outer-join="true"
      cascade="save-update">
      <key column="delivery_did"/>
      <one-to-many class="test.hibernate.Box"/>
    </set>
   
    <set
      name="toys"
      table="toy"
      inverse="true">
      <key column="delivery_did"/>
      <one-to-many class="test.hibernate.Toy"/>
    </set>
   </class>
</hibernate-mapping>


Code:
<hibernate-mapping>
   <class
     name="test.hibernate.Toy"
     table="toy">


     <id
        name="toyID"
        column="tid"
        unsaved-value="null"
        access="field"
        type="integer">        
        <generator class="native"/>
     </id>

    <version name="version" access="field" column="version" type="integer"/>

      <property
        name="description"
        column="descr"
        type="string"/>

   
      <many-to-one
        name="delivery"
        column="delivery_did"
        class="test.hibernate.Delivery"
        not-null="true"/>

      <many-to-one
        name="box"
        column="box_bid"
        class="test.hibernate.Box"
        not-null="false"/>       
   </class>

</hibernate-mapping>


Used Java-Code
Code:
        System.out.println("Starting test ...");

        Configuration config = new Configuration();
        SessionFactory sf = config.configure().buildSessionFactory();

        System.out.println("Loading Delivery ...");

        Session s = sf.openSession();
        Delivery d = (Delivery) s.find("from Delivery").get(0);
        s.close();
        s = sf.openSession();

        Delivery origDelivery = (Delivery) s.find("from Delivery").get(0);
        s.close();

        s = sf.openSession();

        Transaction t = s.beginTransaction();

        // create new box and add it to delivery and add a toy
        Box b = new Box();
        b.setDelivery(d);
        d.getBoxes().add(b);

        Toy toy = (Toy) d.getToys().iterator().next();
        toy.setBox(b);
        b.getToys().add(toy);

        // lock original delivery
        s.lock(origDelivery, LockMode.NONE);

        // save the changed delivery
        s.saveOrUpdateCopy(d);
        t.commit();
        s.close();


And parts of the log-output
Code:
21515 [main] DEBUG net.sf.hibernate.engine.Cascades  - processing cascades for: test.hibernate.Box
21515 [main] DEBUG net.sf.hibernate.engine.Cascades  - cascading to collection: test.hibernate.Box.toys
21515 [main] DEBUG net.sf.hibernate.engine.Cascades  - done processing cascades for: test.hibernate.Box
21515 [main] DEBUG net.sf.hibernate.engine.Cascades  - processing cascades for: test.hibernate.Box
21515 [main] DEBUG net.sf.hibernate.engine.Cascades  - cascading to collection: test.hibernate.Box.toys
21515 [main] DEBUG net.sf.hibernate.engine.Cascades  - cascading to saveOrUpdate()
21515 [main] DEBUG net.sf.hibernate.engine.Cascades  - version unsaved-value strategy UNDEFINED
21515 [main] DEBUG net.sf.hibernate.engine.Cascades  - id unsaved-value strategy NULL
21515 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - saveOrUpdate() previously saved instance with id: 37
21515 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - updating [test.hibernate.Toy#37]
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 37, of class: test.hibernate.Toy
   at net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:1687)
   at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1470)
   at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1490)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1419)
   at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:115)
   at test.hibernate.TestHibernate.main(TestHibernate.java:62)
Exception in thread "main"


if from interest i have a testcase ...

Sure it could be, that i'm doing something really wrong ... therefore it would be great if someone would take a look ...

TiA
curio


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