[jboss-user] [EJB 3.0] - Re: javax.persistence.EntityNotFoundException: deleted entit

abcdefghijklmnop do-not-reply at jboss.com
Mon Mar 23 08:58:28 EDT 2009


"jochen.reinhardt" wrote : So how do you delete the other entities? What does your code look like?
  | 
  | I think the correct way would be to remove the relationship, first. Something like that:
  | 
  |   | // clear the relationship
  |   | // depending on your relation context you may have to call EntityManager.merge(...)
  |   | List<Event> relatedEvents = event.getRelatedEvents();
  |   | for (Event relatedEvent : relatedEvents)
  |   | {
  |   |     relatedEvent.getRelatedEvents().remove(event);
  |   | }
  |   | // on both sides! That's important!
  |   | event.setRelatedEvents(new ArrayList<Event>(0))
  |   | // remove the event
  |   | entityManager.remove(event);
  |   | 
  | 
  | Please try it that way!

That's exactly how I do it. Like I mentioned, the strange thing is, that the error occurs aswell while trying to delete an entity that has no relationships to other events.

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4220222#4220222

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4220222



More information about the jboss-user mailing list