title: How to inject @PersistenceContext into pojo class
body: <p>I'm trying to inject PersistenceContex into POJO using @PersistenceContex annotation, I've read that i need to made that POJO managed to do that. So I inject my POJO class into servlet(so its now managed as dependent object, am i right ?) but when servlet is trying to call metod from injected object i get error:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException:
    Unable to retrieve
    EntityManagerFactory for unitName null</p>
  </blockquote>
  
  <p>So it looks like PersistenceContext is not injected into POJO properly, what should I do to make it work ?</p>
  
  <p>My POJO class looks like this:</p>
  
  <pre><code>public class FileEntityControlerImpl implements FileEntityInterface {
  
  @PersistenceContext
  EntityManager entityManager;
  
  @Override
  public void createFile(FileEntity fileEntity) {
      ...}
  
  @Override
  public FileEntity retriveFile(String fileName) {
      ...}
  </code></pre>
  
  <p>Injection point:</p>
  
  <pre><code>@Inject
  FileEntityInterface fileController;
  </code></pre>
  
  <p>If I use SLSB and inject using @EJB it works fine.</p>
  
  <p>..::UPDATE::..</p>
  
  <p>stacktrace:</p>
  
  <blockquote>
    <p>WARNING: StandardWrapperValve[ResourcesServlet]: PWC1406: Servlet.service() for servlet ResourcesServlet threw exception
    java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName MambaPU
            at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:121)
            at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:162)
            at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:554)
            at pl.zawi.mamba.core.integration.controllers.implementation.FileEntityControlerImpl.retriveFile(FileEntityControlerImpl.java:32)
            at pl.zawi.mamba.core.face.servlets.ResourcesServlet.doGet(ResourcesServlet.java:60)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
            at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
            at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
            at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
            at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
            at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
            at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
            at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
            at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
            at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
            at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
            at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
            at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
            at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
            at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
            at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
            at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
            at java.lang.Thread.run(Thread.java:662)</p>
  </blockquote>
  
  <p>persistance.xml:</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="MambaPU" transaction-type="JTA"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;jta-data-source&gt;jdbc/MambaDB&lt;/jta-data-source&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
          &lt;shared-cache-mode&gt;ALL&lt;/shared-cache-mode&gt;
          &lt;properties&gt;
  &lt;!--            &lt;property name="javax.persistence.jdbc.password" value="root"/&gt;--&gt;
  &lt;!--            &lt;property name="javax.persistence.jdbc.user" value="root"/&gt;--&gt;
  &lt;!--            &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&gt;--&gt;
  &lt;!--            &lt;property name="eclipselink.ddl-generation" value="create-tables"/&gt;--&gt;
  &lt;!--            &lt;property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/&gt;--&gt;
              &lt;property name="eclipselink.logging.level" value="ALL"/&gt;
              &lt;property name="eclipselink.ddl-generation" value="drop-and-create-tables"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>..::UPDATE2::..</p>
  
  <p>If someone is interested there is sorce of my project, I've been using maven so it should be simple to build and run.(MySql drive is not included in pom-s so keep it in mind )</p>
  
  <p><a href="http://www.easy-share.com/1913897916/Mamba.Core.zip" rel="nofollow">Mamba.Core</a></p>