On Aug 26, 2007, at 6:44 PM, Paul Spencer wrote:

I would like to use OpenEJB in the jUnit tests of a maven based EJB3 project. Currently the container managed entity manager, which is injected via the @PersistenceContext annotation, is null. I am using OpenJPA for my JPA implementation.

One thing to verify is that you've filled in the "unitName" attribute of the PersistenceContext annotation and that the unit name matches a persistence unit declared in a META-INF/persistence.xml in the application jar.

We do validate several things about your app, but this particular one is still on the todo list:
  http://issues.apache.org/jira/browse/OPENEJB-453

Even still it should result in failure later.  Hopefully we can find it.

The unit test logs the OpenEJB startup, ending with "INFO - OpenEJB Ready.", and I can get the entityManager by creating an EntityMangerFactory then creating the EntityManager from the factory.

I suspect a configuration error on my part.
Where should I look?

If you're persistence unit was not found when we attempted to resolve the reference (created via the annotation) during the time the bean as loading, we'd throw one of these which should be logged and would fail your app:

throw new IllegalArgumentException("Persistence unit " + contextInfo.persistenceUnitName + " for persistence-context-ref " +
                        contextInfo.referenceName + " not found");

If we attempted to find something for injection and it mysteriously wasn't there, we'd log one of these:

logger.warning("Injection data not found in enc: jndiName='" + injection.getJndiName() + "', target=" + injection.getTarget() + "/" + injection.getName());

If something failed to be injected (missing setter perhaps), we'd log one of these:

logger.warning("Injection: No such property '" + property + "' in class " + beanClass.getName());


We do have a rather large example (our test suite) that has injection of PersistenceContext among other things:

http://svn.apache.org/repos/asf/openejb/trunk/openejb3/itests/openejb- itests-beans/src/main/java/org/apache/openejb/test/stateless/ AnnotatedFieldInjectionStatelessBean.java http://svn.apache.org/repos/asf/openejb/trunk/openejb3/itests/openejb- itests-beans/src/main/resources/META-INF/

Definitely let us know even if you find the issue as we really want everything to be bullet proof. No one should be left scratching their head even if it is there fault -- that should be one of the advantages of embedded testing.

-David

Reply via email to