2 Replies Latest reply on Jun 20, 2008 12:56 AM by charliepower76

    JTA EntityManager cannot access a transactions

    charliepower76

      Hi there,


      I need to manually start, commit (or rollback) a transaction in a javabean. For this, I inject the entityManager, and then call entityManager.getTransaction.start(). However, it always throws an exception :


      Caused by: java.lang.IllegalStateException: JTA EntityManager cannot access a transactions
      



      From what I read, it is caused by Seam using JPA and not JTA, but how can I force it to use JTA while being able to inject the EntityManager in my different classes ?


      Here's the line of my components.xml related to persistance :


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



      and my persistence.xml :


      <persistence-unit name="dcd" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/dcdDatasource</jta-data-source>
                <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
            </properties>
         </persistence-unit>
      



      Is there a line that i need to add to my components.xml to enable JTA ?


      Note : We're not using EJB3 in this project, only POJOs and Hibernate.

        • 1. Re: JTA EntityManager cannot access a transactions
          joaobmonteiro

          Hi Charles,


          It seems that you are using JTA already. The problem is that you are not allowed to get a transaction using SMPC.


          First option:
          - Use a conversation to manage transactions. You could use @Begin(flushMode = Manual) for example.


          Second option:
          - Use an UserTransaction to deal with your problem. Look for UserTransaction and Seam. I know that it is possible but i never try.


          Regards,

          • 2. Re: JTA EntityManager cannot access a transactions
            charliepower76

            I finally got it working by using the UserTransaction object and by switching from JTA to RESOURCE LOCAL for the transaction-type in my persistance.xml. However, I will try using a conversation, it might be a more elegant solution.


            Thanks !