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

I am testing a Seam application using the needle testing API. In my code, I use the getEntityManager () method from EntityHome. When I run unit tests against a database in memory, 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 solve some of these errors by introducing EntityManager with

@In
EntityManager entityManager;

Unfortunately, the persist method EntityHomealso calls getEntityManager. This means a lot of jokes or rewriting code. Is there any workaround and why is all this an exception? By the way, I am using Seam 2.2.0 GA.

. . - http://jbosscc-needle.sourceforge.net/jbosscc-needle/1.0/db-util.html.

+3
1

Seam EntityManager getEntityManager EntityHome?

.

getEntityManager EntityHome, Seam , , entityManager. , Seam , , entityManager, EntityHome Excedption.

getEntityManager EntityHome

public EntityManager getEntityManager() {
    return (EntityMananger) Component.getInstance("entityManager");
}

@In-jected EntityManager, Seam , . , .

, Seam @In-jected . :

@In
EntityManager entityManager;

EntityManager entityManager, Seam , ;

, .

,

+4

Source: https://habr.com/ru/post/1735928/


All Articles