title: Configuration to be able to @Inject EntityManager in Seam 3
body: <p>In my project I use <code>Seam 3</code> and I am having issues injecting the <code>EntityManager</code> with the <code>@Inject</code> annotation. I am pretty sure there is some kind of configuration to make sure the <code>EnityManager</code> knows which <code>PersistenceUnit</code> to use. For example with <code>EJB</code> you can type:  </p>
  
  <pre><code>@PersistenceContext(unitName="MY_PERSISTENCE_UNIT_NAME")
  private EntityManager eManager;
  </code></pre>
  
  <p>which persistence unit is configured in the <code>persistence.xml</code> file. Here is my pseudo configuration:  </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="MY_PERSISTENCE_UNIT_NAME" transaction-type="JTA"&gt;
  
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;jta-data-source&gt;java:jboss/TimeReportDS&lt;/jta-data-source&gt;
          &lt;mapping-file&gt;META-INF/orm.xml&lt;/mapping-file&gt; 
  
          &lt;class&gt;....&lt;/class&gt;
          &lt;class&gt;....&lt;/class&gt;
          &lt;class&gt;....&lt;/class&gt;
  
          &lt;properties&gt;
  
              &lt;property name="jboss.entity.manager.factory.jndi.name"
                  value="java:/modelEntityManagerFactory" /&gt;
  
              &lt;!-- PostgreSQL Configuration File --&gt;
              &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /&gt;
              &lt;property name="hibernate.connection.password" value="password" /&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:postgresql://192.168.2.125:5432/t_report" /&gt;
              &lt;property name="hibernate.connection.username" value="username" /&gt;
  
              &lt;!-- Specifying DB Driver, providing hibernate cfg lookup
                   and providing transaction manager configuration --&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /&gt;
              &lt;property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/&gt;
              &lt;property name="hibernate.transaction.manager_lookup_class"
                  value="org.hibernate.transaction.JBossTransactionManagerLookup" /&gt;
              &lt;property name="hibernate.archive.autodetection" value="class" /&gt;
  
              &lt;!-- Useful configuration during development - developer can see structured SQL queries --&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
              &lt;property name="hibernate.format_sql" value="false" /&gt;
  
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;  
  </code></pre>
  
  <p>I have read some articles about Seam 2 but there the configuration is made in <code>components.xml</code> file by adding the:  </p>
  
  <pre><code>&lt;persistence:managed-persistence-context
          name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/modelEntityManagerFactory" /&gt;
  </code></pre>
  
  <p>inside the <code>&lt;components&gt;</code> tag. The next step in Seam 2 is to add the:  </p>
  
  <pre><code>&lt;property name="jboss.entity.manager.factory.jndi.name"
                  value="java:/modelEntityManagerFactory" /&gt;
  </code></pre>
  
  <p>in the <code>persistence.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence ...&gt;
      &lt;persistence-unit name="MY_PERSISTENCE_UNIT_NAME" ...&gt;
          ...
          &lt;properties&gt;
              ...
  
              &lt;property name="jboss.entity.manager.factory.jndi.name"
                  value="java:/modelEntityManagerFactory" /&gt;
  
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>but it seam that in Seam 3 there is no file <code>components.xml</code>. Also there is no attribute <code>unitName</code> in <code>@Inject</code> annotation to specify the persistence unit.  </p>
  
  <p>So please help me to configure my project so I can use the <code>@Inject</code> with  <code>EntityManager</code> as shown in many examples on the net.  </p>
  
  <p>I use <code>Postgres</code> database and <code>JBoss AS 7</code>.</p>
  
  <p>EDIT: Adding an example. I don't use the <code>EntityManager</code> in an <code>Entity</code> class.</p>
  
  <pre><code>@Named("validateReportAction")
  @SessionScoped
  public class ValidateReportAction extends ReportAction implements Serializable {
  
      private static final long serialVersionUID = -2456544897212149335L;
  
      @Inject
      private EntityManager em;
  ...
  }  
  </code></pre>
  
  <p>Here in this <code>@Inject</code> I get warning from <code>Eclipse</code> "<code>No bean is eligible for injection to the injection point [JSR-299 §5.2.1]</code>"  </p>
  
  <p>If I use the <code>@Inject</code> on some beans that are marked as <code>Entity</code> the <code>@Inject</code> works fine.</p>