3 Replies Latest reply on Apr 24, 2009 8:22 PM by Arbi Sookazian

    can not do persist transaction

    quinten jiang Newbie
      My bean is created with JPA:

      I can see principalModel data coming in, but when I try to create a new Entity Principal, and save it, no transaction happen and no doing insert function, some can find what my problem is?

      thanks,


      @Name("principalAction")
      @Scope(ScopeType.SESSION)
      public class PrincipalAction implements Serializable {

      @In protected EntityManager entityManager;
      @In private PrincipalModel principalModel;

      public void saveMethod() {
              Principal principal = new Principal();
              principal.setFirstName(principalModel.getFirstName());
              principal.setIdentifier(principalModel.getIdentifier());
              entityManager.persist(principal);
          }
      }
        • 1. Re: can not do persist transaction
          Arbi Sookazian Master

          Looks like that is a JavaBean component and not an EJB (SFSB/SLSB).  I'm not sure exactly of the Seam tx semantics for JavaBean components.  Show your entire components.xml code.


          With EJB3/CMT, a transaction is required by default for all business methods (public methods in local/remote interface for you EJB3 class).  The container begins a tx (if required it can join an existing tx), and commits the tx at the end of the method.


          It gets trickier if you're using Hibernate's MANUAL flushMode vs. EJB3 AUTO (default) or COMMIT.

          • 2. Re: can not do persist transaction
            quinten jiang Newbie
            my component.xml like ( working under Jboss):

               <core:init debug="true" jndi-pattern="@jndiPattern@"/>

                    <core:manager concurrent-request-timeout="500"
                             conversation-timeout="120000"
                             conversation-id-parameter="conversationId"
                             parent-conversation-id-parameter="pid"/>

                 <transaction:entity-transaction entity-manager="#{entityManager}"/>
                             
               <persistence:entity-manager-factory name="consoleflexEntityManagerFactory"
                                  persistence-unit-name="consoleflex"/>

               <persistence:managed-persistence-context name="entityManager"
                                                 auto-create="true"
                                      entity-manager-factory="#{consoleflexEntityManagerFactory}" persistence-unit-jndi-name="java:/consoleflexEntityManagerFactory" />



            and persistence.xml:


              <persistence-unit name="consoleflex" transaction-type="RESOURCE_LOCAL">
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <jta-data-source>java:/consoleflexDatasource</jta-data-source>
                  <properties>
                     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
                     <property name="hibernate.hbm2ddl.auto" value="update"/>
                     <property name="hibernate.show_sql" value="true"/>
                     <property name="hibernate.format_sql" value="true"/>
                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/consoleflexEntityManagerFactory"/>
                  </properties>
               </persistence-unit>

            • 3. Re: can not do persist transaction
              Arbi Sookazian Master

              RESOURCE_LOCAL is typically used for Java SE apps.  If you're in a EE envmt (using JBoss AS, for example), you should use JTA instead of RESOURCE_LOCAL.




              Transaction type used. Either JTA or RESOURCE_LOCAL (default to JTA in a JavaEE environment and to RESOURCE_LOCAL in a JavaSE environment). When a jta-datasource is used, the default is JTA, if non-jta-datasource is used, RESOURCE_LOCAL is used.

              So is your Seam app SE or EE??