-->
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: Insert element in list vs update before delete
PostPosted: Tue May 24, 2005 11:09 am 
Newbie

Joined: Tue May 10, 2005 3:57 am
Posts: 5
Hi,

I have a bidirectional many-to-one relationship in a parent/child (email/recipients) table.
In the parent table (email) I have a list of items (recipients). When I remove an item at the end of the list, the row is simply deleted from the recipient table. That is fine.

When I remove a recipient within the list (i.e. not the last one), Hibernate should remove the recipient from the table and it should update the index number of the following items.

What seems to happen is that Hibernate starts by updating the index numbers of the following items and then delete the recipient which I have removed from the list.

This does not work for me because in my Legacy tables there is a constaint on the USERID, NAME, SEQNO (which is my list's index)

So... my question is: Would there be a way for me to tell Hibernate, that it should remove the recipients from the table before updating the seqno of the recipients remaining?

Or is there an other way to do all this?

Thanks you so much for your help!

Jean
Hibernate version: 3.0.4

Mapping documents:

<class name="Email" table="T_EMAIL" >
<composite-id name="ID" class="EmailID" >
<key-property name="userID" column="USERID"/>
<key-property name="name" column="NAME"/>
</composite-id>

<list name="recipients" cascade="all-delete-orphan" inverse="true">
<key>
<column name="USERID"/>
<column name="NAME"/>
</key>
<index column="SEQNO"/>
<one-to-many class="Recipient"/>
</list>
</class>

<class name="Recipient" table="T_RECIPIENT" dynamic-update="true" dynamic-insert="true">
<composite-id name="ID" class="RecipientID">
<key-many-to-one name="alert" class="Alert">
<column name="USERID" length="8"/>
<column name="NAME" length="8"/>
</key-many-to-one>
<key-property name="emailAddress" column="RECIPIENT"/>
</composite-id>

<property name="seqNo" column="SEQNO" not-null="true" type="int" update="true" insert="true"/>
</class>


Code between sessionFactory.openSession() and session.close():
Code:
EmailDAO emailDAO = new emailDAO();
Email email = emailDAO.getByUserIDQNumber("ABCD", "0022");
email.removeRecipient("jean@yyy.com");

HibernateUtil.commitTransaction();
HibernateUtil.closeSession();            



The generated SQL (show_sql=true):

My table TRECIPIENT contains the following fields
Code:
USERID   NAME   SEQNO   RECIPIENT
======   ====   =====   =========
ABCD     0022   1       jean@xxx.com
ABCD     0022   2       jean@yyy.com
ABCD     0022   3       jean@zzz.com

** Unfortunately ** there exist a unique constrain on userid, name. seqno



When I try to remove the second row

The folowing SQL is executed

Code:
update TQRECIPIENT set SEQNO=? where USERID=? and NAME=? and RECIPIENT=?
binding '3' to parameter: 1
binding 'PRDSJT' to parameter: 2
binding '0022' to parameter: 3
binding 'JEAN.TREMBLAY@GG.COM' to parameter: 4
SQL Error: 1, SQLState: 23000
ORA-00001: unique constraint (%s.%s) violated


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.