Archive
Posts Tagged ‘EntityManager’
Seam injection in threads.
November 25, 2009
1 comment
Hi
In seam, when you want to inject some components such as EntityManager,POJOs,or … to threads, Probably you will see all your objects is NULL.
The reason of this scenario is SeamApplicationContext missing in your threads, OK what is the solution?
You should use Lifecycle.begin() and Lifecycle.end() methods before and after your codes :
….
…….
Lifecycle.begin()
EntityManager em = (EntityManager)Component.getInstance(“em”,true);
Lifecycle.End()
……
…
So when you write your codes between these two methods, You will be in the SeamApplicationContext and you will not see any exceptions for EntityManager too like :
EntityManager is closed
no Transaction is in progress
….
..
bye.
Categories: Java, Seam
ApplicationContext, EntityManager, Java, Seam, Thread