title: How do injection with JPA?
body: <p>Is possible do injection in EntityManager with EclipseLink 2.3 ?</p>
  
  <p>This is my persistence.xml file:</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="SuaParte" transaction-type="RESOURCE_LOCAL"&gt;
                  // classes..
          &lt;properties&gt;
              &lt;property name="eclipselink.jdbc.batch-writing" value="JDBC"/&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/schema"/&gt;
              &lt;property name="javax.persistence.jdbc.user" value="root"/&gt;
              &lt;property name="javax.persistence.jdbc.password" value="root"/&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I'm new with JPA so I created this persistence.xml file at first just to test to see if it works, but now I would like to use <code>@PersistenceContext</code> to don't have to worry about manage the <code>EntityMangerFactory</code> and <code>EntityManager</code>.</p>
  
  <p>I'm using Eclipse Indigo Java EE Web Developers with GlassFish v3.</p>
  
  <p><strong>UPDATE:</strong>
  I follow @Andrei Bodnarescu approach and this <a href="http://www.albeesonline.com/blog/2008/08/06/creating-and-configuring-a-mysql-datasource-in-glassfish-application-server/" rel="nofollow noreferrer">tutorial</a> too and everything is fine to get a connection with my database through GF3:</p>
  
  <p><img src="https://i.stack.imgur.com/OTVbc.png" alt="Ping database"></p>
  
  <p>And i change my persistence.xml file:</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="SuaParte" transaction-type="JTA"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;jta-data-source&gt;jdbc/mysql&lt;/jta-data-source&gt;
                  //classes.. 
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>So i try to persist something in my database:</p>
  
  <pre><code>@Stateless
  @LocalBean
  public class DaoUser {
      @PersistenceContext(unitName="SuaParte")
      private EntityManager em;
  
      public void persist(User user){
          try{
              em.persist(user);
              }catch(Exception e){
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>And it returns a <code>java.lang.NullPointerException</code> in <code>em.persist(user);</code>.
  What am I doing wrong ?</p>