In Seam what's the difference between injected EntityManager and getEntityManager from EntityHome

Posted by Navi on Stack Overflow See other posts from Stack Overflow or by Navi
Published on 2010-03-08T13:56:48Z Indexed on 2010/03/14 16:55 UTC
Read the original article Hit count: 413

Filed under:
|
|

I am testing a Seam application using the needle test API. In my code I am using the getEntityManager() method from EntityHome. When I run the unit tests against an in memory database I get the following exception:

java.lang.IllegalStateException: No application context active
at org.jboss.seam.Component.forName(Component.java:1945)
at org.jboss.seam.Component.getInstance(Component.java:2005)
at org.jboss.seam.Component.getInstance(Component.java:1983)
at org.jboss.seam.Component.getInstance(Component.java:1977)
at org.jboss.seam.Component.getInstance(Component.java:1972)
at org.jboss.seam.framework.Controller.getComponentInstance(Controller.java:272)
at org.jboss.seam.framework.PersistenceController.getPersistenceContext(PersistenceController.java:20)
at org.jboss.seam.framework.EntityHome.getEntityManager(EntityHome.java:177)
etc ..

I can resolve some of these errors by injecting the EntityManager with

@In
EntityManager entityManager;

Unfortunately the persist method of EntityHome also calls the getEntityManager. This means a lot of mocks or rewriting the code somehow. Is there any workaround and why is this exception thrown anyway? I am using Seam 2.2.0 GA by the way.

There is nothing special about the components. They are generated by seam-gen. The test is performed with in memory database - I followed the examples in http://jbosscc-needle.sourceforge.net/jbosscc-needle/1.0/db-util.html.

© Stack Overflow or respective owner

Related posts about java

Related posts about seam