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
|
|