aspose file tools*
The moose likes Object Relational Mapping and the fly likes Deleting Entity in ManyToOne relationship - Make foreign key as null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Deleting Entity in ManyToOne relationship - Make foreign key as null" Watch "Deleting Entity in ManyToOne relationship - Make foreign key as null" New topic
Author

Deleting Entity in ManyToOne relationship - Make foreign key as null

akhil achuthan
Ranch Hand

Joined: Mar 29, 2006
Posts: 69
In the below example, i am having ManyToOne relationship from Address to my parent entity Person. Now i am required to set the corresponding foreign key reference in my Person table as null whenever i delete an entry from the Address table.

I am using JPA 2.0 EntityManager.delete(addressEntity) method to delete the Address entity. But i am stuck up with the following exception. Neither my Address entity nor my reference key changed as null in Person table.


Please help me in solving the above said problem.

javax.persistence.RollbackException: Error while committing the transaction
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93)
....
Caused by: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [Person#<null>]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1197)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:81)
... 3 more



Thanks,
Akhil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deleting Entity in ManyToOne relationship - Make foreign key as null