-->
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: unneccessary update?
PostPosted: Fri Oct 17, 2008 5:29 pm 
Newbie

Joined: Sat Aug 23, 2008 3:29 pm
Posts: 7
We are looking at Hibernate to use it in of our new projects. In the test following scenario, An animal can go to multiple shows. I am createing an Animal object, a set of 2 shows and assigning the set to animal object. The logs show that a row is inserted in the Animal table and then 2 rows in the Show table (for 2 shows where this ANimal is supposed to go). Then an update is called to update the Show rows with a value which it is already having. I do not understand why is the update being called? I think I am missing something here. Can someone please help? Thanks in Advance

Code:
<hibernate-mapping>
   <class name="events.Animal" table="Animal">
      <id name="id">
         <generator class="native"></generator>
      </id>
      <property name="name" column="name"></property>
      <set name="shows" inverse="false" cascade="all">
         <key column="aid" not-null="true"/>
         <one-to-many class="events.Show"/>
      </set>
   </class>
   <class name="events.Show" table="Show1">
   <id name="id">
      <generator class="native"/>
   </id>
   <property name="name" column="name"/>

   </class>
</hibernate-mapping>


insert into Animal (name)  values  (?)
Hibernate: insert into Show1 (name, aid) values (?, ?)
Hibernate: insert into Show1 (name, aid) values (?, ?)
Hibernate: update Show1 set aid=? where id=?
Hibernate: update Show1 set aid=? where id=?

MySQL logs

081017 22:20:23         4 Query       insert into Animal (name) values ('horse10')
            4 Query       insert into Show1 (name, aid) values ('london10', 30)
            4 Query       insert into Show1 (name, aid) values ('London11', 30)

            4 Query       update Show1 set aid=30 where id=25 // is aid not already saved as 30 in the previous line?

            4 Query       update Show1 set aid=30 where id=26 // line2
            4 Query       commit


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2008 5:43 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Could it be that you have the problem described here:
http://www.hibernate.org/hib_docs/v3/re ... bidir.html


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.