-->
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: Unique key constraint and cascading deletes
PostPosted: Thu Apr 14, 2005 12:57 pm 
Beginner
Beginner

Joined: Tue Jan 18, 2005 6:44 pm
Posts: 39
1. As far as unique key constraints are concenrned. If I use the saveOrUpdate method for the object will it check only the primary key to decide whether it needs to save or update or will it check the unique key constraint too.
I have the following mapping

<id name="TransId" column="TRANS_ID" type="integer" unsaved-value="undefined">
<generator class="sequence">
<param name="sequence">trans_id_seq</param>
</generator>
</id>
<property name="RequestId" type="string" length="256" not-null="true">
<column name="REQUEST_ID" unique-key="FAS_TRANS_UK"/>
</property>
<property name="UserId" type="string" length="256" not-null="true">
<column name="USER_ID" unique-key="FAS_TRANS_UK"/>
</property>
<property name="FormId" type="string" length="256" not-null="true">
<column name="FORM_ID" unique-key="FAS_TRANS_UK"/>
</property>

Since the primary key is sequence generated the unsaved-value attribute does not stop hibernate from performing a save operation. Is there a way to make hibernate check the unique key constraint before making a decision of issuing an insert or an update?


2. I have tried cascading deletes before for one to many parent child relationships and it has worked well. the only difference with my mapping this time is that the fetch association is set to lazy.

<set name="transactions" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="FORM_ID" on-delete="cascade"/>
<one-to-many class="FasTransaction"/>
</set>

This time instead of first generating a delete for the child record the delete is first generated for the parent which throws a referential integrity constraint violation exception.


Thanks,
Jeevak


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.