Announcement Announcement Module
Collapse
No announcement yet.
JPA, JTA GlassFish - No transaction is currently active exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA, JTA GlassFish - No transaction is currently active exception

    I'm using Spring 3.0.2 with EclipseLink 2.0.0 inside of a GlassFish container. I've got my Dao objects annotated with @Transactional at the class level.

    My persistence.xml has the following defined:
    Code:
    <persistence-unit name="my-pu" transaction-type="JTA">
    My applicationContext.xml has the following bean definitions:
    Code:
        <context:annotation-config />
    
        <tx:jta-transaction-manager />
    
        <tx:annotation-driven/>
    
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
            <property name="persistenceUnits">
                <map>
                    <entry key="my-pu" value="persistence/my-pu"/>
                </map>
            </property>
            <property name="persistenceContexts">
                <map>
                    <entry key="my-pu" value="persistence/my-pu"/>
                </map>
            </property>
        </bean>
    
        <bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="jpaVendorAdapter">
                <bean                class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
                    <property name="showSql" value="true" />
                </bean>
            </property>
            <property name="jpaDialect">
                <bean
                    class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
            </property>
            <property name="persistenceUnitName" value="my-pu"></property>
        </bean>
    Everything seems to be working correctly but I get no data persisted to the database tables. So I invoked getJpaTemplate().flush() to flush the persistence context and the received the following exception:
    Code:
    Exception Description: No transaction is currently active; nested exception is javax.persistence.TransactionRequiredException: 
    Exception Description: No transaction is currently active
    	at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:307)
    	at org.springframework.orm.jpa.DefaultJpaDialect.translateExceptionIfPossible(DefaultJpaDialect.java:120)
    	at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    	at org.springframework.orm.jpa.JpaAccessor.translateIfNecessary(JpaAccessor.java:152)
    	at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:188)
    	at org.springframework.orm.jpa.JpaTemplate.flush(JpaTemplate.java:288)
    Now the problem I have with all of this, besides the fact that nothing is going to the database, is that I have stepped through the Spring code and I do see Spring beginning and committing transactions. It has a handle to the JtaTransactionManager which wraps the UserTransaction from the GlassFish container. I can see the invocation of the commit() being performed on the UserTransaction object, so I know that Spring is starting and committing the transactions. So why does the EntityManager think that there is no current transaction? I believe my configuration is correct based upon the documentation.

    When I start my application and Spring loads the LocalContainerEntityManagerBean I see the following output:
    Code:
    Jun 17, 2010 5:13:36 PM org.springframework.transaction.jta.JtaTransactionManager checkUserTransactionAndTransactionManager
    INFO: Using JTA UserTransaction: com.sun.enterprise.transaction.UserTransactionImpl@3522971b
    Jun 17, 2010 5:13:36 PM org.springframework.transaction.jta.JtaTransactionManager checkUserTransactionAndTransactionManager
    INFO: Using JTA TransactionManager: com.sun.enterprise.transaction.TransactionManagerHelper@71ee88dd
    Jun 17, 2010 5:13:36 PM org.springframework.transaction.jta.JtaTransactionManager initTransactionSynchronizationRegistry
    INFO: Using JTA TransactionSynchronizationRegistry: com.sun.enterprise.transaction.TransactionSynchronizationRegistryImpl@6a0f0c67
    Jun 17, 2010 5:14:33 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
    INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
    So it's clear that Spring is managing the transactions and has found the TransactionSynchronizationRegistry. So why doesn't the EntityManager see that?

    Thanks for the help...
Working...
X