• Post Reply Bookmark Topic Watch Topic
  • New Topic

Deleting Entity in ManyToOne relationship - Make foreign key as null  RSS feed

Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Oh the stink of it! Smell my tiny ad!
Thread Boost - a very different sort of advertising
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!