1 Reply Latest reply on Sep 28, 2007 9:54 PM by wayne baylor

    PersistentObjectException - Help me !!!

    Amer Ramamni Newbie

      I been trying to solve this problem for a couple of days now and no luck!
      a little help would be appreciated. THanks
      I am getting this Exception every time I run my client.

      This is my main class

      
       public static void main(String[] args) {
      
       KBClient c = new KBClient();
       ClassificationRemote r = c.lookupNewClassificationBean();
       //Setting and Adding project
       KnowledgeBase first = new KnowledgeBase();
       Project p = new Project(8);
       p.setProjectName("Test Project");
       p.setDescription("testing");
       first.setKnowledgeID(200);
       first.setKnowledgeName("Demo");
       first.setKnowledgeCategory("Classification");
       first.setProjectID(p);
       r.addProject(p);
       r.addKnowledgeBase(first);
       }
      
       private ClassificationRemote lookupNewClassificationBean() {
       try {
       Hashtable props = new Hashtable();
       props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
       props.put("java.naming.provider.url", "localhost");
       Context c = new InitialContext(props);
       return (ClassificationRemote) c.lookup("ClassificationBeanFinal/remote");
       }
       catch(NamingException ne) {
       System.out.println("here!");
       Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ne);
       throw new RuntimeException(ne);
       }
       }
      


      This is the function in my session bean class
      public void addKnowledgeBase(KnowledgeBase kb){
       KnowledgeBase temp = em.find(KnowledgeBase.class, kb.getKnowledgeID());
       if(temp == null){
       em.persist(kb);
       em.flush();
       }
       }
      


      This is the Exception
      Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: EntityBean.Project
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:734)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:560)
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:369)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:165)
      Caused by: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: EntityBean.Project
       at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
       at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
       at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:182)
      
      

      Thanks for the HELP