2 Replies Latest reply on Jun 17, 2009 2:09 PM by Sudha Perumal

    remove method

    Sudha Perumal Newbie
      can we call remove method in persist?

      I got an error like


      "deleted entity passed to persist: [com.sans.erp.entity.StockDetail#<null>
      "

              @SuppressWarnings({ "unchecked", "deprecation" })
           @Override
           public String persist()
           {
               -------
               --------
                shome.getEntityManager().persist(st);
                shome.getEntityManager().flush();
                  if(----)
                   {
                     sh.getEntityManager().remove(sto);
                System.out.println("remove method called");
                sh.getEntityManager().flush();
                    }
                  return "persisted";

              }
        • 1. Re: remove method
          Gregory Nikle Apprentice

          Hi
          1. your question should be can we call remove after persist?
          2. st is equal sto?
          3. what is shome and sh using entity manager?


          please post well formed source code.

          • 2. Re: remove method
            Sudha Perumal Newbie
            Hi this is my code...

            "@SuppressWarnings({ "unchecked", "deprecation" })
                 @Override
                 public String persist()
                 {
                                    -------
                                    ------
                                StockDetailHome shome=new StockDetailHome();
                           StockDetailList u1=new StockDetailList();
                           StockDetail st=new StockDetail();
                           String sti=u1.getStockAutoId();
                           System.out.println("St_Id:"+sti);
                           st.setStockDetailId(sti);
                           st.setLocation(to);
                           st.setReorderQty(5);
                           st.setQuantity(getInstance().getQty());
                           ItemDetails ii=new ItemDetails();
                           ii.setItemCode(itemcode);
                           st.setItemDetails(ii);
                           shome.getEntityManager().persist(st);
                           shome.getEntityManager().flush();
                           
                           String qu="select stockDetail from StockDetail stockDetail where quantity=0";
                           List<StockDetail> ls=getEntityManager().createQuery(qu).getResultList();
                           if(ls.size()!=0)
                           {
                                for(int i=0;i<ls.size();i++)
                                {
                                     System.out.println("Going to delete");
            StockDetail sto=new StockDetail();
            sto=ls.get(i);
            StockDetailHome sh=new StockDetailHome();
                                     sh.getEntityManager().remove(sto);
                                     System.out.println("remove method called");
                                     sh.getEntityManager().flush();
                                     System.out.println("Deleted");
                                }
            }
                                
                           
                      
            }     
                      return "persisted";
                 }"