3 Replies Latest reply: May 8, 2012 4:29 AM by Rajendra J RSS

    deleted entity passed to persist:

    Mahesh Shinde Newbie

      Hi ,

      I am getting following exception after deletion of entity bean.

      Caused by: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [de.bonprix.orderstarter.model.entity.ArticleSupplier#<null>]
       at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:613)
       at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:299)
       at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:83)
       at de.bonprix.orderstarter.service.ManageOrders.deleteSupplierDetails(ManageOrders.java:476)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
       at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:37)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:63)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
       at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53)
       at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
       ... 77 more
      


      And Below is my code


      @TransactionAttribute(TransactionAttributeType.REQUIRED)
       public void deleteSupplierDetails() {
       if (this.artSuppPriceList != null) {
       for (int i = 0; i < this.artSuppPriceList.size(); i++) {
       ArticleSupplierPrice artSuppPriceObj = this.artSuppPriceList.get(i);
       if (artSuppPriceObj.getIsChecked() != null
       && artSuppPriceObj.getIsChecked().equals(Boolean.TRUE)) {
       entityManager.remove(artSuppPriceObj);
       }
       }
       entityManager.flush();
       }
       }


      I have two entites ArticleSupplier and ArticleSupplierPrice has OneToMany relationship respectively.


      Suggest.


        • 1. Re:  deleted entity passed to persist:
          wayne baylor Apprentice

          looks like your deleting the ArticleSupplierPrice objects from the DB, but not removing ArticleSupplier's references to the objects.

          maybe change your code to something like:

          public void deleteSupplierDetails()
          {
           if (this.artSuppPriceList != null)
           {
           ArticleSupplierPrice[] prices = this.artSuppPriceList.toArray(new ArticleSupplierPrice[0]);
           for(ArticleSupplierPrice price : prices)
           {
           if (price.getIsChecked() != null
           && price.getIsChecked().equals(Boolean.TRUE))
           {
           this.atrSuppPriceList.remove(price); //remove reference cuz you're deleting it
           entityManager.remove(price);
           }
           }
          
           entityManager.flush();
           }
          }
          


          • 2. Re:  deleted entity passed to persist:
            Mahesh Shinde Newbie

            Thanx for your input.

            But I am getting the same exception.

            This exception is occurred only when I am trying to remove ArticleSupplier immediately after persisting this entity.


            • 3. Re:  deleted entity passed to persist:
              Rajendra J Newbie

              Can u pls paste your entity - Need to check relation

               

              1.In relation you are using fetch = FetchType.EAGER change to fetch = FetchType.Lazy

               

               

              2.and cascade = Cascade.ALL

               

              3. Try to remove and check - These all things are for @ManyToOne  relationship

               

              I tried its working....