4 Replies Latest reply on Aug 17, 2005 6:05 AM by Emmanuel Bernard

    Exception: detached entity passed to persist:

    Mike Duffy Novice

      When a user logs on to our web app, we find the User object by the username and then we store that object in the session for future use.

      We see a problem when we try to composite the User object in another object. As an example, if the user goes to a comment form and fills out a comment, we create a Comment object that contains a reference to the User object from the session (assume in this made up example that the comment table contains a column for the userid).

      When we go to persist the Comment object we get the exception listed below. If the relationship is mapped as "one to one" and cascade is set to ALL, shouldn't the User object be merged into the current context and everything should work fine? But it doesn't. I've also tried calling merge on the User object before I call persist on the Comment object and the same exception is still thrown.

      Any suggestions would be greatly appreciated.

      BTW: There was a similar post on this topic that was casued by using the wronng annotation to call the Entity Manager. That is not my problem.

      Thx.

      Mike

      03:43:18,043 WARN [RequestProcessor] Unhandled Exception thrown: class javax.ejb.EJBException
      03:43:18,049 ERROR [[action]] Servlet.service() for servlet action threw exception
      javax.ejb.EJBException: null; CausedByException is:
      detached entity passed to persist: com.forbintechnologies.tracker.entitymodel.User
      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:46)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:70)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:72) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:93)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:183) at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
      at org.jboss.aspects.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:30)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
      at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:79)
      at $Proxy83.create(Unknown Source)
      at com.forbintechnologies.tracker.delegates.IssueDelegate.create(IssueDelegate.java:57)
      at com.forbintechnologies.tracker.struts.actions.ProcessIssueCreateAction.execute(ProcessIssueCreateAction.java:131)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)