-->
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: Simple update results in multiple SQL calls
PostPosted: Fri Oct 31, 2003 11:07 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:15 am
Posts: 22
Hi all

I have a one-to-many relationship between zone and asset (a zone has many assets). It's mapped both ways - on zone side it's <set>, one asset it's <many-to-one>

I retrieved an asset, then a zone that is different to the one currently associated to the asset, and set the asset's zone to the new one. That is:

Asset asset = session.load(Asset.class, new Long(123L));
Zone zone = session.load(Zone.class, new Long(456L));
if (asset.getZone() != zone) { // and I know this is true
asset.setZone(zone);
}

I saw that Hibernate issue multiple SQL, first to update all columns in the ASSET table, including the ZONE_ID column. Then, Hibernate issued another SQL to nullify the ASSET.ZONE_ID column. Finally, a third SQL sets the ASSET.ZONE_ID to the new value.

However the following calls resulted correctly in only 1 update:

asset.setName("ABC");
asset.setWeight(20);
asset.setValue(100d);

The ASSET table is actually much more complicated. It has self-joins (parent and child assets) and a lot of many-to-ones and sets to other tables. I can attach the mapping file.

I've also tried building a simplier version of a 1:m relationship and update the many-side object with a new parent. However, I am _not_ able to simulate this behaviour. Hibernate correctly issues only 1 SQL.

So, I would like to know _in general_ what causes Hibernate to issue nullify a column? What causes it to update all columns in a table? Or where should I start looking to debug this?

Thanks
Kevin


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 12:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Do you have inverse="true"?


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Mon Nov 03, 2003 10:23 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:15 am
Posts: 22
Hi Gavin

Thanks! It's working with the inverse="true" now.

Rgds


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.