1 Reply Latest reply on Jun 6, 2011 5:55 AM by gadeyne.bram

    entityManager remains null using @In

    gadeyne.bram

      Hi,


      My setup:
      jboss 6.0.0.Final
      Seam 2.2.2.Final
      MySQL 5.5.12


      I'm trying to connect a MySQL database using persistence. From what I've learned it should be possible to use @In EntityManager entityManager; afterwards to obtain a conversation scoped entityManager. This however is always null.


      I have a local-tx-datasource configured like this:


      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE datasources PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
                                   "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
      <datasources>
       <local-tx-datasource>
        <jndi-name>cosaraWebTestDatasource</jndi-name>
        <use-java-context>true</use-java-context>
        <connection-url>jdbc:mysql://localhost:3306/seam</connection-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <user-name>root</user-name>
        <password>root</password>
       </local-tx-datasource>
      </datasources>
      



      then my persistence.xml is set up like this:


      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <persistence 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_1_0.xsd" 
                   version="1.0">
                   
         <persistence-unit name="CosaraWebTest" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/cosaraWebTestDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="validate"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.default_catalog" value="seam"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/cosaraWebTestEntityManagerFactory"/>
            </properties>
         </persistence-unit>
          
      </persistence>
      



      finally my components.xml contains the following:


      <persistence:managed-persistence-context name="entityManager" auto-create="true"
                                 persistence-unit-jndi-name="java:/cosaraWebTestEntityManagerFactory"/>
      



      This is my session scoped bean:


      @Name("columnKeeper")
      @Scope(ScopeType.SESSION)
      public class ColumnKeeper implements Serializable, DropListener {
      ...
      @In
      EntityManager entityManager;
      ...
      }
      



      entityManager is always null.


      I've also added "create = true" and "scope = ScopeType.CONVERSATION"


      I've also tried changing @In to @PersistenceContext


      When I look at my mysqlAdmin I can see that the JBOSS server has created a connection with the my MySQL server.


      Can someone help?


      With kind regards
      Bram Gadeyne