-->
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: Problem about update on collection of composite-element
PostPosted: Thu Jun 28, 2007 11:42 pm 
Newbie

Joined: Mon Apr 09, 2007 6:25 am
Posts: 4
Dear all,

I have two tables. Table A and Table B has a one-to-many relationship. Each table A record can have several records in B, and table B itself has no primary key.
Therefore i only defined mapping file for Table A and inside it there is a collection attribute like this:

<set name="bSet" table="TABLEB" lazy="false" fetch="join" cascade="save-update, delete, all-delete-orphan">
<key>
<column name="colA"/> <!-- an attribute in table A -->
</key>
<composite-element class="tableB">
<property name="colB" type="date" column="COLB" />
<!-- some other table B columns -->
</composite-element>
</set>

which is a set of TableB objects.
Whenever i do an update of the TableA object, the update will be propagated to this collection and update statements on Table B will be generated even if i didn't modify anything in the collection.

For example, there is one tableB object in the collection without any modification and i update the tableA object. After the update statement on Table A, there will be first a delete statement on Table B, followed by insert statement on Table B. The delete statement is to delete the one tableB object and then the record is re-insert into Table B. It seems the result will be the same. However, the delete statement fails to delete the record when any of the fields in the composite-element contains null. The generated delete statement is like this:
delete from TABLEB where colA=? and colB=?
and a null is bind to the colB, which makes it something like
delete from TABLEB where colA=X and colB=null
which fails to delete the target record.
Since the delete fails to delete anything, and the insert proceeds, then there contains duplicate records.
I think one cause of this might because table B doesn't contain a primary key, therefore all columns attributes become part of the where clause and affect it when it is null.

Does anyone encountered that before? Is it really the correct behavior of hibernate? Is there any solution?

Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 01, 2007 9:34 am 
Newbie

Joined: Mon Apr 09, 2007 6:25 am
Posts: 4
Has anyone met that problem too?

Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 4:29 am 
Newbie

Joined: Thu Jun 21, 2007 8:01 am
Posts: 5
is this perhaps related to this thread [1] ?

[1] http://forum.hibernate.org/viewtopic.php?t=976741


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.