0 Replies Latest reply on Dec 30, 2011 10:32 AM by Thomas Müller

    ObenEntityManagerInView with EJB and ZK

    Thomas Müller Newbie

      Looking for a best parctice solution to handle OpenEntityManagerInView with Ajax framework ZK.


      I have DAO-EJBs to retrieve DOs with lazy collections. When i load the DOs and access the lazy collections in an ZK-Execution-Cycle (AJAX-Event-Requestcycle) i get of cource a lazyinitialisation exception because the transaction of the EntityManager is already closed.


      First t tried to handle the transaction of the EntityManager manualy and used a RESOURCE LOCAL datasource with open and close of the EntityManager/Transaction in an ZK-execution listener. I created an EntityManager Producer with ZK-ExecutionScope to inject it in my DAOs. I got ContextNotActive exeptions when i tried to access the injected EntityManager.


      Next i tried to use container managed JTA datasources in my DAO-EJBs and retrieved the UserTransaction by lookup in my ZK-execution lifecycle listener and startet and closed the UserTransaction there. I hoped the EJB would use this transaction, but i still got LazyInitialisationExeptions. I also tried also em.joinTransaction() in my stateless session beans but without success.


      I'm wondering if seam offers a solution or utils to deal with this. The seam-faces module has probably already solved this for JSF. I searched the forum, read the persistence and solder documents but did not find a good starting point. Seam-transaction might also deal with this but i found no documentation.


      What i would like to have are Ejbs with JTA datasource EntityManager and transaction bound to the lifecycle of a ZK-Execution.


      /thomas