0 Replies Latest reply on May 6, 2008 1:28 AM by Carlos Diógenes

    conflicting configurations of persistence.xml

    Carlos Diógenes Newbie

      Hi guys,


      I'm using JBoss 4.2.2.GA and Seam 2.0.1.GA and I'm with a problem trying to use an EntityManager in a validator.


      If a configure my persistence.xml file this way:


      <persistence-unit name="sadau">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/sadauDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
               <property name="hibernate.hbm2ddl.auto" value=""/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/sadauEntityManagerFactory/sadauData"/>
            </properties>
         </persistence-unit>



      And inject the EntityManager in the validator I get a NullPointerException when I try to access it.


      I follow the instructions here: http://docs.jboss.com/seam/2.0.1.GA/reference/en/html_single/#d0e5972


      If I configure my persistence.xml as:


      <persistence-unit name="sadau" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/sadauDatasource</jta-data-source>
            <non-jta-data-source>java:/sadauDatasource</non-jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
               <property name="hibernate.hbm2ddl.auto" value=""/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/sadauEntityManagerFactory"/>
            </properties>
         </persistence-unit>



      I can get the EntityManager by calling the following in the validator (wihtout injecting it):


      emf = Persistence.createEntityManagerFactory ("sadau");
              em = emf.createEntityManager();



      But with this configuration, when I try to persist some entity in the database I get the following:


      Exception during request processing:
      Caused by javax.servlet.ServletException with message: "#{fatorHome.persist}: javax.persistence.TransactionRequiredException: no transaction is in progress"



      I hope that this is enough information to describe and realize what is happening here. If more information is needed, please say. I'm new to this world (JBoss, Seam, Hibernate, EJB) and I will also be very grateful if in addition to a solution to this problem, someone also point me to documentation or books that can help me understand the underlines of this problem.


      Thanks,
      Carlos.