-
1. Re: javax.persistence.EntityNotFoundException: deleted entit
jochen.reinhardt Mar 22, 2009 7:25 PM (in response to abcdefghijklmnop)Hi!
Strange name, but OK...
Please post your full error message with stack trace. Nevertheless, it seems to me like you have some on delete cascade in your m:n relationship.
I can't really tell, may be you remove some referenced entities, and afterwards, you remove the referencing entity, which in turn tries to delete the referenced entities again. So please be more precise about your m:n relationship.
Best regards,
Jochen -
2. Re: javax.persistence.EntityNotFoundException: deleted entit
jochen.reinhardt Mar 22, 2009 7:30 PM (in response to abcdefghijklmnop)Amendment to my last post: I guess, this may also happen in a recursive manner. I mean, having some entity types A and B, by deleting some instance of A you may get:
delete A,
delete all B referenced by A
delete all A referenced by all B's affected by step 2
and so on...
Please correct me, f I am mistaken... -
3. Re: javax.persistence.EntityNotFoundException: deleted entit
abcdefghijklmnop Mar 22, 2009 8:48 PM (in response to abcdefghijklmnop)Here are the error messages:
WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@4004ec javax.persistence.EntityNotFoundException: deleted entity passed to persist: [model.Event#<null>] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:598) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:513) at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101) at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:263) at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86) at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177) at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1414) at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135) at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75) at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:170) at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87) at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:219) at org.jboss.ejb3.proxy.handler.ProxyInvocationHandlerBase.invoke(ProxyInvocationHandlerBase.java:261) at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:101) at $Proxy1030.delete(Unknown Source) at web.EventJSF.deleteEvent(EventJSF.java:191) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.el.parser.AstValue.invoke(AstValue.java:170) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) at javax.faces.component.UICommand.broadcast(UICommand.java:387) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)
My entity looks like this (that's the important part I guess):class Event { ... @ManyToMany(fetch = FetchType.EAGER) private List<Event> relatedEvents; }
Notice that it's a self-referencing relationship so maybe there's something wrong with that.
Like I wrote in my first post, I delete the references manually before deleting the entity. I can tell from the database that all references are removed correctly so that shouldn't be the problem. -
4. Re: javax.persistence.EntityNotFoundException: deleted entit
jochen.reinhardt Mar 23, 2009 6:43 AM (in response to abcdefghijklmnop)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! -
5. Re: javax.persistence.EntityNotFoundException: deleted entit
wolfgangknauf Mar 23, 2009 6:47 AM (in response to abcdefghijklmnop)Hi abc,
take a look at this document, hopefully you will find your use case:
http://www.jboss.org/community/docs/DOC-13222
Basically, it should tell you the same as Jochen said.
Wolfgang -
6. Re: javax.persistence.EntityNotFoundException: deleted entit
abcdefghijklmnop Mar 23, 2009 8:58 AM (in response to abcdefghijklmnop)"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. -
7. Re: javax.persistence.EntityNotFoundException: deleted entit
wolfgangknauf Mar 23, 2009 10:30 AM (in response to abcdefghijklmnop)Hi,
I didn't see that you have a self referencing relationship, sorry for that.
What is the expected behavior? Do you want to delete all related events if one event is removed? This makes only sense if you build a tree structure. If you have a net of relationships, you shouldn't cascade the removal.
If you want to cascade, I think you have to do some recursion and use the code Jochen provided to remove all childs of all childs of all childs of ...
If you don't want to cascade, Jochen's code should work.
Hope this helps
Wolfgang