File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Can not remove a EJB 3 entity and the error is: violation of foreign key constraint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Can not remove a EJB 3 entity and the error is: violation of foreign key constraint " Watch "Can not remove a EJB 3 entity and the error is: violation of foreign key constraint " New topic
Author

Can not remove a EJB 3 entity and the error is: violation of foreign key constraint

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 550
Hi,

I am trying to write a code to remove a entity which has collection of other entitiies as one to many relation. My source code for the one to many and many to one relations are like:


In Contract class which which has a collection of Branches.





In Branch class which has a collection of BranchMemberItem





In BranchMemberItem class:


I think I have all correct codes in place and sped long time finding what is wrong but I am still getting this error. If you know what is wrong wit my code, please let me know.


raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 550
Hi,

Any comment on this?

Thanks.
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
That is odd, I would expect it to delete BranchMemberItem first. Perhaps include the SQL trace.
Do you have any other relationships/foreign keys or cycles?

TopLink Essentials did have some issue with delete of OneToMany's that used a join table, but you seem to be using a foreign key so should be ok.
You may be able to remove your objects in two stages using flush(), or remove the database constraint.

Most of the deletion constraint issues in TopLink Essentials were fixed in EclipseLink, so you may consider upgrading.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can not remove a EJB 3 entity and the error is: violation of foreign key constraint
 
Similar Threads
I found that inner classes cause problem run my jar file (no problem making the jar or compiling),
problem with insert and select
how to use parseInt()
Jtable and database results
nullPointerException on entity manager methods