2 Replies Latest reply on Sep 7, 2008 5:52 PM by he youlin

    Transaction.instance().setRollbackOnly() or Transaction.instance().rollback()cause detatched entity

    he youlin Novice

      hi.
      I have some confusion in CONVERSATION scope entitymanager.


      I have a conversation scope compenent. When i call a function with
      Transaction.instance().setRollbackOnly() or Transaction.instance().rollback() it will cause session closed and throw org.hibernate.LazyInitializationException: could not initialize proxy - no Session


      have  anybody some suggestion?

        • 2. Re: Transaction.instance().setRollbackOnly() or Transaction.instance().rollback()cause detatched entity
          he youlin Novice
          
          No.
          If remove Transaction.instance().setRollbackOnly() it work fine.
          Otherwise must change
           
            @Factory
               public void getFibres()
               {
                    
               pageSize=pageSize==null?10:pageSize;
                  String sql="from WsFibre i where lower(i.fibreNo) like :search " +
                      "or lower(i.fibreType) like :search or lower(i.receiveNo) like :search " +
                      "or lower(i.location) like :search or lower(i.selBatch) like :search " +
                      "or lower(i.selBatch) like :search or lower(i.inBatch) like :search " +
                      "or lower(i.outBatch) like :search " ;
                            
                  fibres= entityManager.createQuery(sql)
                            .setParameter("search", getSearchPattern()).getResultList();
               }
          
          to
          
            @Factory
               public void getFibres()
               {
                    
               pageSize=pageSize==null?10:pageSize;
                  String sql="from WsFibre i join fetch i.item where lower(i.fibreNo) like :search " +
                      "or lower(i.fibreType) like :search or lower(i.receiveNo) like :search " +
                      "or lower(i.location) like :search or lower(i.selBatch) like :search " +
                      "or lower(i.selBatch) like :search or lower(i.inBatch) like :search " +
                      "or lower(i.outBatch) like :search " ;
                            
                  fibres= entityManager.createQuery(sql)
                            .setParameter("search", getSearchPattern()).getResultList();
               }
          
          
          
          add  join fetch i.item