-->
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: One-to-Many Bidirectional Inverse Issue
PostPosted: Wed Jul 15, 2009 5:21 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
Suppose i have one-to-many bidirectional association between Category and Item
In Category.hbm.xml:
<class name="Category" table="CATEGORY">
<set name="items" cascade="save-update">
<key>
<column name="CAT_ID" not-null="true" />
</key>
<one-to-many class="Item" />
</set>
</class>

and

In Item.hbm.xml:
<many-to-one name="category" class="Category" update="false" insert="false" column name="CAT_ID" />

Suppose i have a category with 2 items and now i am saving category object.
insert into HBLEARN1.CATEGORY (CNAME, CID) values ('Computer', 100)
insert into HBLEARN1.ITEM (INAME, ITEMID, CAT_ID) values ('Pen', 1, 100)
insert into HBLEARN1.ITEM (INAME, ITEMID, CAT_ID) values ('Pencil', 2, 100)
update HBLEARN1.ITEM set CAT_ID=100 where ITEMID=1 and CAT_ID=100
update HBLEARN1.ITEM set CAT_ID=100 where ITEMID=2 and CAT_ID=100

NOTE1 : I have not specified inverse="true" attribute on items collection in mapping.
NOTE2 : The many-to-one side is mapped with update="false" and insert="false"


Now there are 2 changes to inmemoery persistence instances. but as i have marked many-to-one side as update="false"
and insert="false", it will not participate in any SQL. Moreover as there is no inverse="true" specified at one-to-many side,
it will participate in insert/update SQL's. here i am saving category and items. So i understand the insert statements.

Problem A)why it is firing 2 item update statements?
FYI: if i specify inverse="true" on one-to-many side, these 2 update statements are not fired..

Problem B)In Java persistence with hibernate book its written that, i can switch the inverse side. The <many-to-one> element
doesn’t have an inverse attribute, but we can map it with update="false" and insert="false" to effectively ignore it
for any UPDATE or INSERT statements. If i do this (no inverse="true" on one-to-many side and insert="false" and
update="false" on many-to-one side), still i get those 2 update statements?


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.