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 with cascade delete
PostPosted: Sun Aug 26, 2007 3:49 am 
Newbie

Joined: Sun Mar 18, 2007 12:15 pm
Posts: 19
I havent found any solutions to my problem with "Delete", can anyone in this forum help me?


The setup is like,,, a Department can have many Professors.
I have a table for the Department, and a table for Persons. Linking them together I have a table called Professor.
Instead of having a many to many relationship, I am using many-to-one and one-to-many. The reason is that the Professor table must contain arbitrary data. Also, this is the recomended way according to documentation.

My problem is... when deleting a Person,,, I get an error saying that I am breaking a reference constraint. There is a reference to the Person I am going to delete in the Professor table.

To me it seem like NHibernate is deleting objects in the wrong order. It should have been deleting the referenced object in the Professor table before deleting the Person.
Of course could I manually delete the object in the Professor table,,,,,,, but I prefer to let the NHibernate do the job.


Department:
Code:
...
...
<bag name="Professor"  inverse="false" table="Professor" cascade="all-delete-orphan" lazy="false" >
   <key column="ProfId"></key>
   <one-to-many class="Professor,asm"/>
</bag>
...
...


DepartmentProfessor (Table Professor )
Code:
....
....
<many-to-one column="Person" name="Person" class="Person, asm" cascade="save-update" lazy="false"></many-to-one>
....
....



Person:
Code:
....
....
<bag name="Professor" inverse="false" table="Professor" cascade="all-delete-orphan" lazy="false">
   <key column="Person"></key>
   <one-to-many class="Professor,asm"></one-to-many>
</bag>
....
....


What am I doing wrong?
//regards Lasse


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 27, 2007 11:53 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Your professors bag in Person should be inverse (='true'). Have you been having problems with inserts? Or are your foreign keys in Professor nullable?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 27, 2007 12:59 pm 
Newbie

Joined: Sun Mar 18, 2007 12:15 pm
Posts: 19
marcal wrote:
Your professors bag in Person should be inverse (='true'). Have you been having problems with inserts? Or are your foreign keys in Professor nullable?


Changing inverse to 'true' did not change anything.
The foregn key in Table Professor was nullable. I did change this by adding not-null="true" into the DepartmentProfessor. Examine the database showed that the foregn keys in Professor no longer was nullable.

But ,,, still same problems exists,,,, tries to remove Person before DepartmentProfessor.


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.