[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.eclipselink] Re: Eclipselink JTA without jndi

We were able to do this by extending the org.eclipse.persistence.transaction.JTATransactionController
and returning the spring jta manager package org.foo;
public class MyJtaTransactionController extends JTATransactionController {
private static TransactionManager tm;

@Override
protected TransactionManager acquireTransactionManager() throws Exception {
return tm;
}
public static TransactionManager getTm() {
return tm;
}


   public static void setTm(TransactionManager tm) {
       MyJtaTransactionController.tm = tm;
   }
}

This class is used by eclipselink if you define the property:
eclipselink.target-server=org.foo.MyJtaTransactionController

In your spring config you can inject the transaction manager into the static fields
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.foo.MyJtaTransactionController"/>
<property name="targetMethod" value="setTm"/>
<property name="arguments">
<list>
<ref bean="MyTxMgr"/>
</list>
</property>
</bean>


You might also need to set a post processor to set the datasource correctly
public class MyPersistenceUnitPostProcessor implements PersistenceUnitPostProcessor {


private DataSource jtaDataSource;
public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo mutablePersistenceUnitInfo) {
mutablePersistenceUnitInfo.setJtaDataSource(getJtaDataSource());
}


   public DataSource getJtaDataSource() {
       return jtaDataSource;
   }

   public void setJtaDataSource(DataSource jtaDataSource) {
       this.jtaDataSource = jtaDataSource;
   }
}

	<bean id="postProcessorList" class="java.util.ArrayList">
		<constructor-arg index="0">
			<list>
				<bean id="myPostProcessor"
					class="org.foo.MyPersistenceUnitPostProcessor">
					<property name="jtaDataSource"
						ref="dataSource" />
				</bean>
			</list>
		</constructor-arg>
	</bean>
	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
..
		<property name="persistenceUnitPostProcessors" ref="postProcessorList" />
	</bean>

Good luck!