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
|