Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Eclipselink JTA without jndi
Eclipselink JTA without jndi [message #383020] Thu, 13 November 2008 19:47 Go to next message
Daniel is currently offline Daniel
Messages: 4
Registered: July 2009
Junior Member
is there any way to use eclipselink with JTA and not have a JNDI
datasource? We are currently using hibernate which allows this easily but
would like to switch to eclipselink
Re: Eclipselink JTA without jndi [message #383022 is a reply to message #383020] Fri, 14 November 2008 14:03 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon Yorke
Messages: 77
Registered: July 2009
Member
Yes, Its as easy as not specifying a transactional datasource but
continuing to set the userExternalController flag.

In JPA specify the PU type to be JTA but provide a non transactional
datasource under jta-datasource tag. Or skip the datasources entirely and
just provide direct connection information.
--Gordon
Re: Eclipselink JTA without jndi [message #383024 is a reply to message #383022] Fri, 14 November 2008 14:44 Go to previous messageGo to next message
Daniel is currently offline Daniel
Messages: 4
Registered: July 2009
Junior Member
Thanks for your reply,
How do I set the userExternalController flag? I don't see this property
anywhere. To clarify, I am using an XA datasource and spring's transaction
manager instead of a container managed transaction manager. The error I
was getting was that jtaDataSource was not being set.
Re: Eclipselink JTA without jndi [message #383026 is a reply to message #383024] Fri, 14 November 2008 16:27 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon Yorke
Messages: 77
Registered: July 2009
Member
Are you using JPA? If you are using the non JPA Spring integration then
you should not have to do anything special. If you are using JPA then
just set the XA datasource as your jta-datasource in the persistence.xml
file.

Can you provide details on the exception that you saw. What are the
details on your system's architecture and configuration.
--Gordon
Re: Eclipselink JTA without jndi [message #383042 is a reply to message #383026] Tue, 18 November 2008 21:53 Go to previous messageGo to next message
Daniel is currently offline Daniel
Messages: 4
Registered: July 2009
Junior Member
The exception is

org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
Exception Description: PersistenceUnitInfo PU has transactionType JTA, but
doesnt have jtaDataSource.

We are using JPA and are using spring's
LocalContainerEntityManagerFactoryBean.
Here is an example that works with hibernate:
<bean id="entityManagerFactory"
class=" org.springframework.orm.jpa.LocalContainerEntityManagerFacto ryBean ">
<property name="jpaVendorAdapter">
<bean class="${jpa.adapter}">
<property name="databasePlatform"
value="${jpa.platform}" />
<property name="showSql" value="${jpa.showSql}" />
<property name="generateDdl" value="${jpa.generateDdl}" />
</bean>
</property>
<property name="persistenceXmlLocation"
value="classpath:META-INF/my-persistence.xml" />
<property name="dataSource" ref="myDataSource" />
<property name="jpaPropertyMap" ref="jpaConfig" />
</bean>
and here is a sample persistence xml:

<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="PU" transaction-type="JTA">
<class>com.foo.MyEntity</class>
</persistence-unit>
</persistence>
The spring integration works with eclipselink when using non jta
transaction type. We are using a spring datasource and not jndi.

Gordon Yorke wrote:

> Are you using JPA? If you are using the non JPA Spring integration then
> you should not have to do anything special. If you are using JPA then
> just set the XA datasource as your jta-datasource in the persistence.xml
> file.

> Can you provide details on the exception that you saw. What are the
> details on your system's architecture and configuration.
> --Gordon
Re: Eclipselink JTA without jndi [message #387105 is a reply to message #383042] Thu, 16 April 2009 14:26 Go to previous messageGo to next message
Andre Ribeiro is currently offline Andre Ribeiro
Messages: 58
Registered: July 2009
Member
Has anyone successfully configured EclipseLink JTA without JNDI ? (with
Spring?)
Could you point me some example files/projects ?

Thanks!

Daniel wrote:
> The exception is
>
> org.eclipse.persistence.exceptions.EntityManagerSetupExcepti on
> Exception Description: PersistenceUnitInfo PU has transactionType JTA,
> but
> doesnt have jtaDataSource.
>
> We are using JPA and are using spring's
> LocalContainerEntityManagerFactoryBean.
> Here is an example that works with hibernate:
> <bean id="entityManagerFactory"
>
> class=" org.springframework.orm.jpa.LocalContainerEntityManagerFacto ryBean ">
>
> <property name="jpaVendorAdapter">
> <bean class="${jpa.adapter}">
> <property name="databasePlatform"
> value="${jpa.platform}" />
> <property name="showSql" value="${jpa.showSql}" />
> <property name="generateDdl"
> value="${jpa.generateDdl}" />
> </bean>
> </property>
> <property name="persistenceXmlLocation"
> value="classpath:META-INF/my-persistence.xml" />
> <property name="dataSource" ref="myDataSource" />
> <property name="jpaPropertyMap" ref="jpaConfig" />
> </bean>
> and here is a sample persistence xml:
>
> <persistence version="1.0"
> xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
> <persistence-unit name="PU" transaction-type="JTA">
> <class>com.foo.MyEntity</class>
> </persistence-unit>
> </persistence>
> The spring integration works with eclipselink when using non jta
> transaction type. We are using a spring datasource and not jndi.
>
> Gordon Yorke wrote:
>
>> Are you using JPA? If you are using the non JPA Spring integration
>> then you should not have to do anything special. If you are using
>> JPA then just set the XA datasource as your jta-datasource in the
>> persistence.xml file.
>
>> Can you provide details on the exception that you saw. What are the
>> details on your system's architecture and configuration.
>> --Gordon
>
>
Re: Eclipselink JTA without jndi [message #387108 is a reply to message #387105] Thu, 16 April 2009 15:14 Go to previous message
Daniel is currently offline Daniel
Messages: 4
Registered: July 2009
Junior Member
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.MethodInvokingFacto ryBean ">
<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.LocalContainerEntityManagerFacto ryBean ">
...
<property name="persistenceUnitPostProcessors" ref="postProcessorList" />
</bean>

Good luck!
Previous Topic:@Version field does partially update?
Next Topic:TopLink issue 3868 fixed in EclipseLink?
Goto Forum:
  


Current Time: Wed Oct 22 15:41:58 GMT 2014

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

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