0 Replies Latest reply on Mar 5, 2012 7:46 AM by rodrigo.uchoa

    Can POJO and EJB seam components share the same transactional context?


      Hey everyone!


      I'm having a strange problem where sometimes I get the "(Hibernate) session is closed" error before the seam conversation is ended. I think it might have to do with the fact that our business layer is composed with both simple POJO Seam components and also with EJB Seam Components. Our design is something like this:




      As you can see all classes in our service layer extend our BaseService class, which is annotated with @Transactional and not @TransactionAttribute. Since some of the Service classes are POJOs and others are EJBs, sometimes they need to participate in the same transactional context: A business method call might be initiated from a POJO service, and that POJO might delegate some logic to EJBs and other POJOs and they would all need to be in the same transaction.


      From my initial tests all went well. But Then I started noticing that sometimes the hibernate session was being closed prematurely when an EJB service was being called. All our business layer calls are intercepted by a custom interceptor we created:



      //this code is executed inside an interceptor
      returnedValue = invocation.proceed();
      //some other stuff goes on here, and sometimes the hibernate session is already closed at this point



      It seems that the JTA transaction is being closed right after the EJB's method call is finished when invocation.proceed() is executed, but at that point out interceptor still needs the Session. The strange thing is that this only occurs sometimes, and only when an EJB service is used, remote or not.



      Any clues?