I can successfully use an EntityManger that has been injected into a stateless session bean using an @PersistenceContext(unitName="Dictionary") annotation.
If I try to set up a reference to the same unit using an ejb-jar.xml as shown:
Code:
<enterprise-beans>
<session>
<ejb-name>Ejb3EntityDescriptorServiceBean</ejb-name>
<persistence-context-ref>
<persistence-context-ref-name>persistence/Dictionary</persistence-context-ref-name>
<persistence-unit-name>Dictionary</persistence-unit-name>
<injection-target>
<injection-target-class>net.sf.moksha.ejb3.util.impl.Ejb3EntityDescriptorServiceBean</injection-target-class>
<injection-target-name>_em</injection-target-name>
</injection-target>
</persistence-context-ref>
</session>
</enterprise-beans>
The container (JBoss 4.0.5.GA as set up by JEMS installer 1.0.2.GA) starts ok and my code runs as far as being able to print out the type of the injected entity manager:
Code:
14:50:02,531 DEBUG [Ejb3EntityDescriptorServiceBean] _em is: org.jboss.ejb3.entity.TransactionScopedEntityManager@e229be
However, any attempt to get the _em reference to do "anything useful" in a method annotated with @PostConstruct results in a stack trace that ends:
Code:
Caused by: java.lang.NullPointerException
at org.jboss.ejb3.entity.ManagedEntityManagerFactory.getNonTxEntityManager(ManagedEntityManagerFactory.java:58)
at org.jboss.ejb3.entity.ManagedEntityManagerFactory.getTransactionScopedEntityManager(ManagedEntityManagerFactory.java:163)
at org.jboss.ejb3.entity.TransactionScopedEntityManager.contains(TransactionScopedEntityManager.java:198)
at net.sf.moksha.ejb3.util.impl.Ejb3EntityDescriptorServiceBean.init(Ejb3EntityDescriptorServiceBean.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.jboss.ejb3.interceptor.LifecycleInvocationContextImpl.proceed(LifecycleInvocationContextImpl.java:159)
at org.jboss.ejb3.interceptor.LifecycleInterceptorHandler.postConstruct(LifecycleInterceptorHandler.java:109)
... 57 more
I'm convinced that the unit name and bean name are correct.
I'm less sure about persistence-context-ref-name, what should this point to?
Has anyone got ejb-jar.xml based injection of a persistence unit working?
Thanks
Andy