1 Reply Latest reply on Apr 13, 2008 6:20 PM by Pete Muir

    EntityNotFoundException after removing entity

    Javier Ferrero Newbie

      Hi everybody!


      I have one entity Process with a OneToMany relation with another entity KillerQuestion as follows:


      @OneToMany(cascade = CascadeType.ALL, mappedBy = "processId")
          private List<KillerQuestion> killerQuestionCollection;
      



      In one SFSB I oftenly refresh the process calling the following method:


      private void refreshProcess(){
             try{
                  em.refresh(process);
              } catch (EntityNotFoundException exc){
                  System.out.println("EntityNotFoundException");
              }
      }
      



      If I open 2 different windows in my explorer and:


      1. Delete one KillerQuestion entity in one window


      2. Refresh the process in the other window using the method showed above


      I get an EntityNotFoundException.


      I would like that if I refresh the process entity in the second window, the process would be refreshed correctly.


      I have tryed to get again from the EM the process entity as follows:


      private void refreshProcess(){
             try{
                  em.refresh(process);
              } catch (EntityNotFoundException exc){
                  System.out.println("EntityNotFoundException");
                  em.find(Process.class,processId);
              }
      }
      



      but I got an exception because the transaction is no longer active:


      16:06:40,802 ERROR [JDBCExceptionReporter] Transaction is not active: tx=Transac
      tionImple < ac, BasicAction: -588b52d0:623:47fe0ca2:b95 status: ActionStatus.ABO
      RT_ONLY >; - nested throwable: (javax.resource.ResourceException: Transaction is
       not active: tx=TransactionImple < ac, BasicAction: -588b52d0:623:47fe0ca2:b95 s
      tatus: ActionStatus.ABORT_ONLY >)
      16:06:40,802 INFO  [DefaultLoadEventListener] Error performing load command
      org.hibernate.exception.GenericJDBCException: Cannot open connection
      



      Concerning this issue I have the following questions:


      1. Is there a way to avoid the EntityNotFoundException and that the process is refreshed properly?


      2. Is there a way to reactivate the transaction so that I can execute the em.find method after the EntityNotFoundException?


      Thanks for your help.


      Cheers



        • 1. Re: EntityNotFoundException after removing entity
          Pete Muir Master

          Javier Ferrero wrote on Apr 10, 2008 07:50 PM:


          Hi everybody!

          I have one entity Process with a OneToMany relation with another entity KillerQuestion as follows:

          @OneToMany(cascade = CascadeType.ALL, mappedBy = "processId")
              private List<KillerQuestion> killerQuestionCollection;
          



          In one SFSB I oftenly refresh the process calling the following method:

          private void refreshProcess(){
                 try{
                      em.refresh(process);
                  } catch (EntityNotFoundException exc){
                      System.out.println("EntityNotFoundException");
                  }
          }
          





          Why do you do that? It's a pretty ugly design.




          1. Is there a way to avoid the EntityNotFoundException and that the process is refreshed properly?

          Yes, use managed entities.


          2. Is there a way to reactivate the transaction so that I can execute the em.find method after the EntityNotFoundException?


          No.