5 Replies Latest reply on Jan 19, 2009 6:48 PM by Val Sw

    xxxHome.remove error javax.persistence.EntityNotFoundException: deleted entity passed to persist

    Val Sw Expert
      Hi,

      When I try to call experimentHome.remove, I am stuck with this error, please help, I tried various options ..:(

      Error:
      ----------------------
      ERROR [application] javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.ExperimentHistoryRecords#<null>]
      javax.faces.el.EvaluationException: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.ExperimentHistoryRecords#<null>]
           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
      ----------------------

      ExperimentHome.java
      -------------------
      public String remove(){     
           super.getInstance().getProject().getQuantExperiment().remove(getInstance());
           return super.remove();
      }

      Experiment.java entity
      ----------------------
      @Entity(name = "Experiment")
      public class Experiment implements Equals, HashCode, ToString
      {
           
           protected List<ExperimentHistoryRecords> ExperimentHistoryRecords;
           protected Project project;

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

           public void setExperimentHistoryRecords(List<ExperimentHistoryRecords> ExperimentHistoryRecords) {
               for(ExperimentHistoryRecords qehr : ExperimentHistoryRecords){
                    qehr.setQuantExperiment(this);
               }
              this.ExperimentHistoryRecords = ExperimentHistoryRecords;
          }

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

           public void setProject(Project project) {
                this.project = project;
           }
           ....
      }

      ExperimentHistoryRecords.java entity
      ------------------------------------
      @Entity(name = "ExperimentHistoryRecords")
      public class ExperimentHistoryRecords implements Equals, HashCode, ToString
      {
           protected Experiment Experiment;
           protected Project project;

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

           public void setQuantExperiment(Experiment value) {
              this.Experiment = value;
          }

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

           public void setProject(Project value) {
              this.project = value;
          }
        • 1. Re: xxxHome.remove error javax.persistence.EntityNotFoundException: deleted entity passed to persist
          Val Sw Expert
          Any help on the above issue appreciated... I tried various options but missing the sequence to remove instance of child from parent before calling remove.... stuck .. :(

          Error:
          ----------------------
          ERROR [application] javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.ExperimentHistoryRecords#<null>]
          javax.faces.el.EvaluationException: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.ExperimentHistoryRecords#<null>]
          at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
          ----------------------
          • 2. Re: xxxHome.remove error javax.persistence.EntityNotFoundException: deleted entity passed to persist
            Val Sw Expert

            Anyone can please help.. I also placed it in Hibernate forum but no response.. :((((

            • 3. Re: xxxHome.remove error javax.persistence.EntityNotFoundException: deleted entity passed to persist
              Pedro Sena Newbie

              Why are you using this:



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



              What is the relationship between QuantExperiment and Experiment ?


              Regards,


              Pedro Sena

              • 4. Re: xxxHome.remove error javax.persistence.EntityNotFoundException: deleted entity passed to persist
                Val Sw Expert
                First of all thanks a lot for replying. Sorry for the typo in previous post.

                a) There are 3 entities Project, QuantExperiment and QuantExperimentHistoryRecords, please refer below.

                b) "super.getInstance().getProject().getQuantExperiment().remove(getInstance());" is used to delete a QuantExperiment, first we need to remove the reference of child from parent before calling "quantExperimentHome.remove()" that is why it is used otherwise it will give the error as "javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.QuantExperiment#<null>".

                c) We added the QuantExperimentHistoryRecords later to track the history of QuantExperiments, information is stored correctly.

                But now when I try to delete QuantExperiment by calling "quantExperimentHome.remove()" it gives the following error : plsssss suggest...

                Error:
                ----------------------
                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>]
                at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)


                Project.java entity
                -------------------
                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<QuantExperimentHistoryRecords> getQuantExperimentHistoryRecords() {
                        if (quantExperimentHistoryRecords == null) {
                             quantExperimentHistoryRecords = new ArrayList<QuantExperimentHistoryRecords>();
                        }
                        return this.quantExperimentHistoryRecords;
                    }
                    setter....

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

                QuantExperiment.java entity
                ---------------------------
                public class QuantExperiment implements Equals, HashCode, ToString {
                protected Project project;
                protected List<QuantExperimentHistoryRecords> quantExperimentHistoryRecords;

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

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

                QuantExperimentHistoryRecords.java entity
                -----------------------------------------
                public class QuantExperimentHistoryRecords implements Equals, HashCode, ToString {
                     protected Project project;
                     protected QuantExperiment quantExperiment;

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

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

                • 5. Re: xxxHome.remove error javax.persistence.EntityNotFoundException: deleted entity passed to persist
                  Val Sw Expert

                  Anyone please suggest what should I try in quantExperimentHome.remove() before calling super.remove()