-->
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: how to ignore foreign key constraint violation
PostPosted: Wed Mar 08, 2006 2:56 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
@Entity
class Department {
....
}


@Entity
class Employee{

@ManyToOne
@NotFound(action=NotFoundAction.IGNORE)
public Department getDepartment()

}


Employee table refers to department table (foreign key).
When I tried to delete a department, I got an exception
"foreign key constraint violation"

I want Hibernate/database to ignore the constraints and delete the department. how?

How to tell Hibernate not to generate the foreign key constraints?
@NotFound(action=NotFoundAction.IGNORE) does not work for this purpose, only for reading, ignore when not found.


Thank you very much for your help.
Dave


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 10:18 am 
Newbie

Joined: Wed Mar 08, 2006 9:36 am
Posts: 4
First of all, are you sure you want to end up with a bunch of orphaned records (employees pointing to non-existent departments)? Forcing your application to ignore referential integrity will almost always come back to haunt you. Moreover, it's not hibernate, but the database that is complaining. You define foreign key constraints in your schema precisely for the purpose of preventing orphaned records. Therefore, the easiest way to get what you are asking is to remove your foreign key constraints.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 8:40 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Thanks for info.
How to tell Hibernate not to generate foreign key constraints for the specific associations?

I am sure it is what I need.
I do not want to remove these constraints manually from database everytime I deploy the application.

Thanks!


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.