Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » EclipseLink, JTA, GlassFish Embedded - No transaction is currently active exception
EclipseLink, JTA, GlassFish Embedded - No transaction is currently active exception [message #541325] Sun, 20 June 2010 00:04 Go to next message
Eclipse UserFriend
I'm using Spring 3.0.2 with EclipseLink 2.0 and GlassFish 3.0.1. I'm having a Transaction issue that is preventing me from inserting data into the database tables. I've annotated my Dao classes with the following on the class:

@Transactional(propagation = Propagation.REQUIRED)


My BaseDao contains the annotation for the @PersistenceContext as follows:
    @PersistenceContext
    public void setEntityManager(EntityManager entityManager) {
        jpaTemplate = new JpaTemplate(entityManager);
    }


My aplicationContext.xml file has the following definitions:
    <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>


and my test-applicationContext.xml has the following:
    <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 name="persistenceUnitManager">
            <bean 
                class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"/>
        </property>
    </bean>   


Things seem to be working except nothing commits to the database. I've stepped through the Spring code and I have confirmed that the JtaTransactionManager is indeed retrieved from the GlassFish container. So I decided to force a flush() on the JpaTemplate, but this raised an exception from the EclipseLink EntityManager and stated that there is no active Transaction.

My container is a GlassFish embedded and the TransactionManager is an active JtaTransactionManager. I step through the Spring code and I can see the interceptors begining the transaction and committing it when it is suppose to. So why does EclipseLink not know about the active Transaction?

I have the following specified in my persistence.xml file:

  <persistence-unit name="my-pu" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/myDataSource</jta-data-source>


So EclipseLink is expecting a JtaTransaction to be running, which it is, and I can see that Spring is actively managing my transactions with the JtaTransactionManager retrieved from GlassFish JNDI. Actually, it is performing the lookup using:

    <tx:jta-transaction-manager />


and it appears that Spring is locating the TransactionSynchronizationRegistry, so it's clear that there is a JtaTransactionManager and the transaction is being started and committed by Spring. So why doesn't EclipseLink see it?

I've stepped into the EclipseLink EntityManagerImpl code and it appears that the exception is being raised at line 694 from the verifyOpen() invocation. What is most interesting about this is that when I perform a persist operation, EntityManager.persist(Entity e), in that method of the EntityManagerImpl a call is made to verifyOpen() as well, but no exception is raised; only when I perform a flush().

So I've spent the past 3 days with this issue trying to find a way around this but I simply can't, so any help that you can give me is greatly appreciated.

Thanks for the help...
Re: EclipseLink, JTA, GlassFish Embedded - No transaction is currently active exception [message #541821 is a reply to message #541325] Tue, 22 June 2010 11:56 Go to previous messageGo to next message
Eclipse UserFriend
You need to set your EclipseLink ServerPlatform to SunAS9ServerPlatform so that EclipseLink can integrate with JTA in Glassfish.

You can set the "eclipselink.target-server" persistence.xml property to "SunAS9".

Re: EclipseLink, JTA, GlassFish Embedded - No transaction is currently active exception [message #541829 is a reply to message #541821] Tue, 22 June 2010 12:23 Go to previous message
Eclipse UserFriend
http://upload.wikimedia.org/wikipedia/en/3/3d/Homer_D%27oh.png

D'oh!!!
Previous Topic:NullPointerException from Hashtable via IndirectMap
Next Topic:Criteria API + countDistinct + composite primary key
Goto Forum:
  


Current Time: Wed Jul 23 21:18:06 EDT 2025

Powered by FUDForum. Page generated in 0.18872 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top