-->
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.  [ 5 posts ] 
Author Message
 Post subject: Update statements for collections updating the key field and
PostPosted: Thu Aug 19, 2004 8:55 am 
Newbie

Joined: Mon Aug 16, 2004 8:36 am
Posts: 7
Location: Canada
Hibernate version:
2.1.6
Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

Debug level Hibernate log excerpt:

Hi All,

Has anyone encountered a situation where Update statements for collections are attempting to update the key field as well as the index field. I am seeing a situation where after inserting records into a collections table (representing a mapped array), hibernate then tries to update those records with the index value for each record but in those updates is also trying to update the key field incorrectly. Any ideas? Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 10:53 am 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
This seems unlikely. Could you post your mapping documents and schema info?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 11:13 am 
Newbie

Joined: Mon Aug 16, 2004 8:36 am
Posts: 7
Location: Canada
Here's the mapping document:

<hibernate-mapping>
<class name="acme.membership.domain.JMember">
<id name="id" type="int" unsaved-value="0">
<generator class="increment"></generator>
</id>
<property name="lastName" />
<property name="firstName" />
<property name="birthDate" type="calendar" />
<joined-subclass name="acme.membership.domain.PrimaryMember"
table="primarymember">
<key column="id" />
<array name="dependents" table="dependent"
cascade="save-update">
<key column="id" />
<index column="i" />
<one-to-many class="acme.membership.domain.Dependent" />
</array>
<many-to-one name="address" cascade="save-update" />
<many-to-one name="contactInfo" cascade="save-update" />
</joined-subclass>
<joined-subclass name="acme.membership.domain.Dependent"
table="dependent">
<key column="id" />
<property name="type" />
</joined-subclass>
</class>
</hibernate-mapping>



Have a look at this trace (with SQL and binding info is enabled):

Some correct inserts into the dependent table occured previously, and now Hibernate is doing some subsequent updates and updating both the id field ('id') as well as the index field ('i').
....
Hibernate: update dependent set id=?, i=? where id=?
21:21:13,785 DEBUG IntegerType:46 - binding '1' to parameter: 1
21:21:13,785 DEBUG IntegerType:46 - binding '2' to parameter: 3
21:21:13,785 DEBUG IntegerType:46 - binding '0' to parameter: 2
Hibernate: update dependent set id=?, i=? where id=?
21:21:13,785 DEBUG IntegerType:46 - binding '1' to parameter: 1
21:21:13,785 DEBUG IntegerType:46 - binding '3' to parameter: 3
21:21:13,785 DEBUG IntegerType:46 - binding '1' to parameter: 2
21:21:13,795 WARN JDBCExceptionReporter:38 - SQL Error: -803, SQLState: 23505
21:21:13,795 ERROR JDBCExceptionReporter:46 - [IBM][CLI Driver][DB2/NT] SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "AMANJI.DEPENDENT" from having duplicate rows for those columns. SQLSTATE=23505


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 1:23 pm 
Newbie

Joined: Mon Aug 16, 2004 8:36 am
Posts: 7
Location: Canada
Would any further information be helpful, would folks consider this a possible Hibernate bug?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 8:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is of course not a bug. You mapped you collection fk column to the same column as the pk column of the joined-subclass table.

Also, you probably intend to use a parent/child association, so read the doco on this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.