title: TomEE + EclipseLink: EntityManager injection not working
body: <p>I'm trying to get this <a href="http://docs.oracle.com/javaee/6/tutorial/doc/giqst.html" rel="nofollow">JPA + EJB + Facelets example</a> running in TomEE Web Profile.
  Because the sample uses EclipseLink, I downloaded EclipseLink and copied <code>eclipselink/jlib/eclipselink.jar</code> into the <code>TomEE/lib</code> directory.</p>
  
  <p><strong>Question 1:</strong> Is this the only file I need to copy over?</p>
  
  <p>I have a number of <code>Entity</code> classes, one JSF SessionScoped ManagedBean to serve web requests, one Stateful EJB to handle database requests, and one more EJB that loads data into the database on start-up.</p>
  
  <p>Code snippets of the ManagedBean and Stateful EJB are below:</p>
  
  <pre><code>@Singleton
  @Startup
  public class ConfigBean {
      @EJB
      private RequestBean request;
  
      @PostConstruct
      public void createData() {
          request.createPart("1234-5678-01", 1, "ABC PART", new java.util.Date(),
                  "PARTQWERTYUIOPASXDCFVGBHNJMKL", null);    
          // more code here...
      }
  }
  
  @Stateful
  public class RequestBean {
      private static Logger logger = Logger.getLogger("order.ejb.RequestBean");
      @PersistenceContext
      private EntityManager em;
  
      public void createPart(String partNumber, int revision, String description,
              java.util.Date revisionDate, String specification,
              Serializable drawing) {
          try {
              Part part = new Part(partNumber, revision, description,
                      revisionDate, specification, drawing);
              em.persist(part); // &lt;--- EXCEPTION THROWN HERE
          } catch (Exception ex) {
              throw new EJBException(ex.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>When the line <code>em.persist(part);</code> in RequestBean tries to execute, I get the following exception:</p>
  
  <pre><code>WARNING: Injection: No such property 'order.ejb.RequestBean/em' in class order.ejb.RequestBean
  May 22, 2012 12:38:39 AM org.apache.openejb.core.transaction.EjbTransactionUtil handleSystemException
  SEVERE: The bean instance business method encountered a system exception: The transaction has been marked rollback only because the bean encountered a non-application exception :javax.ejb.EJBException : null
  javax.ejb.EJBTransactionRolledbackException: The transaction has been marked rollback only because the bean encountered a non-application exception :javax.ejb.EJBException : null
      at org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:350)
      at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:288)
      at order.ejb.RequestBean$LocalBeanProxy.createPart(order/ejb/RequestBean.java)
      at order.ejb.ConfigBean.createData(ConfigBean.java:35)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext$LifecycleInvocation.invoke(ReflectionInvocationContext.java:213)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
      at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176)
      at org.apache.openejb.monitoring.StatsInterceptor.PostConstruct(StatsInterceptor.java:104)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
      at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138)
      at org.apache.openejb.BeanContext.newInstance(BeanContext.java:1368)
      at org.apache.openejb.core.singleton.SingletonInstanceManager.createInstance(SingletonInstanceManager.java:174)
      at org.apache.openejb.core.singleton.SingletonInstanceManager.access$100(SingletonInstanceManager.java:66)
      at org.apache.openejb.core.singleton.SingletonInstanceManager$1.call(SingletonInstanceManager.java:115)
      at org.apache.openejb.core.singleton.SingletonInstanceManager$1.call(SingletonInstanceManager.java:113)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at org.apache.openejb.core.singleton.SingletonInstanceManager.getInstance(SingletonInstanceManager.java:124)
      at org.apache.openejb.core.singleton.SingletonInstanceManager.initialize(SingletonInstanceManager.java:90)
      at org.apache.openejb.core.singleton.SingletonInstanceManager.start(SingletonInstanceManager.java:81)
      at org.apache.openejb.core.singleton.SingletonContainer.start(SingletonContainer.java:118)
      at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:795)
      at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:506)
      at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:634)
      at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:588)
      at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:117)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
      at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
  Caused by: javax.ejb.EJBException
      at order.ejb.RequestBean.createPart(RequestBean.java:59)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
      at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176)
      at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:95)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
      at org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:129)
      at org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:45)
      at org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:66)
      at org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:72)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
      at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
      at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138)
      at org.apache.openejb.core.stateful.StatefulContainer.businessMethod(StatefulContainer.java:648)
      at org.apache.openejb.core.stateful.StatefulContainer.invoke(StatefulContainer.java:353)
      at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:260)
      at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:240)
      at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:91)
      at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:284)
      ... 45 more
  </code></pre>
  
  <p>As I'm not very familiar with the magic that is Java EE I have almost no idea what is going wrong here, but I'd love to know what is causing the first line in the stack trace, above:</p>
  
  <pre><code>WARNING: Injection: No such property 'order.ejb.RequestBean/em' in class order.ejb.RequestBean
  </code></pre>
  
  <p><strong>Question 2:</strong> For some reason injection of the Entity Manager doesn't seem to be working. Anyone have any idea why?</p>
  
  <p>For completeness, below is my <code>persistence.xml</code>, which is in the <code>project/src/main/webapp/classes/META-INF/</code> directory:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0"
      xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit name="order" transaction-type="JTA"&gt;
          &lt;jta-data-source&gt;jdbc/__default&lt;/jta-data-source&gt;
          &lt;properties&gt;
              &lt;property name="eclipselink.ddl-generation" value="drop-and-create-tables" /&gt;
              &lt;property name="eclipselink.ddl-generation.output-mode"
                  value="both" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>Source Code</strong></p>
  
  <p>In case anyone wants to see the directory structure, source code, configuration files, etc. of the project, I've uploaded it to <a href="https://github.com/alexaverbuch/order" rel="nofollow">github here</a>.</p>