Hi, I've been investigating using injected EntityManager into jersey resources to get context managed transactions. I've gotten it to work with Glassfish 3 but have failed to get it working with OpenEJB which I would prefer to be using.
The jersey issue http://java.net/jira/browse/JERSEY-230 describes both a preferred implementation and a fix done for Glassfish 1,5 years ago (fix might be relevant?). I've implemented a resource called PersonResource as desribed in the issue with a persistance unit called "testunit" and it works with Glassfish 3.0.1 (I can successfully make a transaction using the injected EntityManager), but with Tomcat 6/OpenEJB 3.1.3 I get a null reference for the EntityManager i.e it doesn't seem to be injected. The OpenEJB log indicates that things get initialized correctly (?) at deployment: 2011-01-01 01:11:47,966 - INFO - Configuring enterprise application: /home/bjorn/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/jpatest2 2011-01-01 01:11:48,115 - INFO - Configuring PersistenceUnit(name=testunit) 2011-01-01 01:11:48,127 - INFO - Auto-creating a Resource with id 'Default JDBC DatabaseNonJta' of type 'DataSource for 'testunit'. 2011-01-01 01:11:48,127 - INFO - Configuring Service(id=Default JDBC DatabaseNonJta, type=Resource, provider-id=Default JDBC Database) 2011-01-01 01:11:48,128 - INFO - Creating Resource(id=Default JDBC DatabaseNonJta) 2011-01-01 01:11:48,148 - INFO - Adjusting PersistenceUnit testunit <jta-data-source> to Resource ID 'Default JDBC Database' from 'jdbc/test' 2011-01-01 01:11:48,148 - INFO - Adjusting PersistenceUnit testunit <non-jta-data-source> to Resource ID 'Default JDBC DatabaseNonJta' from 'null' 2011-01-01 01:11:48,164 - INFO - Enterprise application "/home/bjorn/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/jpatest2" loaded. 2011-01-01 01:11:48,164 - INFO - Assembling app: /home/bjorn/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/jpatest2 2011-01-01 01:11:48,824 - INFO - PersistenceUnit(name=testunit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 655ms 2011-01-01 01:11:48,913 - INFO - Jndi(name=PersonResourceLocalBean) --> Ejb(deployment-id=PersonResource) 2011-01-01 01:11:48,959 - INFO - Created Ejb(deployment-id=PersonResource, ejb-name=PersonResource, container=Default Stateless Container) 2011-01-01 01:11:48,959 - INFO - Deployed Application(path=/home/bjorn/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/jpatest2) 2011-01-01 01:11:49,201 - INFO - Configuring enterprise application: /home/bjorn/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/openejb 2011-01-01 01:11:49,232 - INFO - Enterprise application "/home/bjorn/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/openejb" loaded. 2011-01-01 01:11:49,232 - INFO - Assembling app: /home/bjorn/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/openejb 2011-01-01 01:11:49,232 - INFO - Deployed Application(path=/home/bjorn/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/openejb) I'm guessing a different implementation using separate classes for the bean and resource might work but I'm not really sure how to do that and would prefer the implementation as is described in http://java.net/jira/browse/JERSEY-230 /Björn
