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:
My BaseDao contains the annotation for the @PersistenceContext as follows:Code:@Transactional(propagation = Propagation.REQUIRED)
My aplicationContext.xml file has the following definitions:Code:@PersistenceContext public void setEntityManager(EntityManager entityManager) { jpaTemplate = new JpaTemplate(entityManager); }
and my test-applicationContext.xml has the following: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>
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.Code:<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>
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:
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:Code:<persistence-unit name="my-pu" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>jdbc/myDataSource</jta-data-source>
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?Code:<tx:jta-transaction-manager />
Thanks for the help...


Reply With Quote
