0 Replies Latest reply on Feb 10, 2009 11:24 PM by valatharv

    Help on javax.persistence.EntityNotFoundException: deleted entity passed to persist - Sorry for reposting

    valatharv
      First of all sorry I am posting the issue again after long time. I tried other forums also but no success, I would really appreciate any help.... pls... Our first phase with seam application is almost complete, we are left with this urgent issue.

      I am sure there is something minor which I am missing and mind be easy for any one of you.

      Issue : When I try to remove QuantExperiment entity, using quantExperimentHome.remove(), I get the following error.
      Error:
      ------
      INFO  [STDOUT] CHECK, QuantExperimentHistoryRecords HJID is = 665, and QuantExperiment HJID is : 303
      INFO  [STDOUT] CHECK, QuantExperimentHistoryRecords HJID is = 666, and QuantExperiment HJID is : 303

      ERROR [application] javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.QuantExperimentHistoryRecords#<null>]
      javax.faces.el.EvaluationException: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.QuantExperimentHistoryRecords#<null>]
      .....................

      --For testing I am printing the id of both the entities in remove(), which is displayed in log above.

      --Note : We are using "super.getInstance().getProject().getQuantExperiment().remove(getInstance());" else it will give the same error for QuantExperiment.
      i.e. "javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.QuantExperiment#<null>]"

      Please help on the following error, I have tried various options but no success :(

      QuantExperimentHome.java
      -------------------------
      public String remove(){     
           
           ////JUST TO CHECK////
           List<QuantExperimentHistoryRecords> qeHr= getInstance().getQuantExperimentHistoryRecords();          
           int xs=qeHr.size();          
           for(int i=0;i<xs;i++){               
                QuantExperimentHistoryRecords qeg=qeHr.get(i);     
                //entityManager.remove(qeg); // TRIED THIS ALSO
                System.out.println("CHECK, QuantExperimentHistoryRecords HJID is = "+qeg.getHjid()+", and QuantExperiment HJID is : "+qeg.getQuantExperiment().getHjid());
           }
           ////END CHECK////

           super.getInstance().getProject().getQuantExperiment().remove(getInstance());     
           return super.remove();
      }


      @Entity(name = "QuantExperiment")
      public class QuantExperiment implements Equals, HashCode, ToString
      {
           protected List<QuantExperimentHistoryRecords> quantExperimentHistoryRecords;
           protected Project project;

           @OneToMany(cascade = {CascadeType.ALL},fetch = FetchType.LAZY, mappedBy="quantExperiment")
           public List<QuantExperimentHistoryRecords> getQuantExperimentHistoryRecords() {
                if (quantExperimentHistoryRecords == null) {
                     quantExperimentHistoryRecords = new ArrayList<QuantExperimentHistoryRecords>();
                }
                return this.quantExperimentHistoryRecords;
           }

           @ManyToOne(fetch = FetchType.LAZY, optional=false)
           public Project getProject() {
                return project;
           }
      }

      @Entity(name = "QuantExperimentHistoryRecords")
      public class QuantExperimentHistoryRecords implements Equals, HashCode, ToString {
           
           protected Project project;
           protected QuantExperiment quantExperiment;

           @ManyToOne(fetch = FetchType.LAZY, optional=false)
           public QuantExperiment getQuantExperiment() {
                return quantExperiment;
           }

           @ManyToOne(fetch = FetchType.LAZY, optional=false)
           public Project getProject() {
                return project;
           }
      }

      @Entity(name = "Project")
      public class Project implements Equals, HashCode, ToString
      {
           protected List<QuantExperiment> quantExperiment;
           protected List<QuantExperimentHistoryRecords> quantExperimentHistoryRecords;

           @OneToMany(cascade = {CascadeType.ALL},fetch=FetchType.LAZY, mappedBy="project")
          public List<QuantExperiment> getQuantExperiment() {
              if (quantExperiment == null) {
                  quantExperiment = new ArrayList<QuantExperiment>();
              }
               return this.quantExperiment;
          }

           @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy="project")
          public List<QuantExperimentHistoryRecords> getQuantExperimentHistoryRecords() {
              if (quantExperimentHistoryRecords == null) {
                  quantExperimentHistoryRecords = new ArrayList<QuantExperimentHistoryRecords>();
              }
              return this.quantExperimentHistoryRecords;
          }
      }