Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Spring Transactions with ecliplink jpa(Spring Transactions with ecliplink jpa)
Spring Transactions with ecliplink jpa [message #1858338] Wed, 29 March 2023 12:54
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
Hi ,

We are planning to migrate from toplink to eclipselink in our project .
In Toplink we have transactions taken care by Spring TopLinkTransactionManager .

So in eclipselink i wanted to test transaction with spring managed JpaTransactionManager and transaction type is resource_local. The problem is transactions are not getting committed to database.
But with entitymanger.getTransaction.commit ,transactions are getting commited.

Could you please let me know if i need any other settings to do.

below are my configurations.

Persistence.xml:
<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_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>group.id.domain.Employee</class>
<class>group.id.domain.Department</class>
<properties>
<property name="javax.persistence.jdbc.driver" value=" />
<property name="javax.persistence.jdbc.url" value="" />
<property name="javax.persistence.jdbc.user" value="" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="ALL" />
<property name="eclipselink.logging.parameters" value="true" />
<!-- from iau-maris-opa -->
<property name="eclipselink.jdbc.bind-paramaters" value="true"
<property name="eclipselink.target-database" value="Oracle" />
<property name="eclipselink.persistence-context.flush-mode" value="commit" />
<property name="eclipselink.persistence-context.reference-mode" value="WEAK" />
<property name="eclipselink.weaving" value="static" />
<property name="eclipselink.weaving.eager" value="true" />
<property name="eclipselink.jdbc.exclusive-connection.mode" value="Always"/>
<property name="eclipselink.session.customizer" value="de.bund.bamf.InGe.bo.MySessionCustomizer"/>
</properties>
</persistence-unit>
</persistence>

springcontext.xml

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

<property name="persistenceXmlLocation" value="classpath:persistence.xml" />
<!-- <property name="dataSource" ref="dataSource" />-->
<property name="persistenceUnitName" value="persistenceUnit" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.Oracle10Platform"/>
</bean>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
</property>
<property name="jpaPropertyMap">
<props>
<prop key="eclipselink.weaving">false</prop>
</props>
</property>
<property name="loadTimeWeaver">
<bean class=
"org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>


And i have also configured sessioncustomizer as follows

DatabaseLogin login = (DatabaseLogin)((ServerSession)session).getDatasourceLogin();
login.setPlatformClassName("org.eclipse.persistence.platform.database.Oracle10Platform");
login.setUsesExternalConnectionPooling(true);
login.setUsesExternalTransactionController(true);

NativeSequence daf = new NativeSequence();
daf.setName("Native");
daf.setPreallocationSize(1);
login.setDefaultSequence(daf);

ConnectionPolicy cp = new ConnectionPolicy();
cp.setPoolName("default");
cp.setShouldUseExclusiveConnection(true);
cp.setIsLazy(false);
((ServerSession)session).setDefaultConnectionPolicy(cp);

((ServerSession)session).setDatasourceLogin(login);
Map<Class, ClassDescriptor> descriptors ;
descriptors =session.getDescriptors();
Project pr = new Project();
pr.setDescriptors(descriptors);
pr.setLogin(login);
pr.setDatasourceLogin(login);
((ServerSession) session).setProject(pr);
((ServerSession) session).setLogin(login);







[Updated on: Wed, 29 March 2023 12:56]

Report message to a moderator

Previous Topic:Transactions not working in junit with eclipselink
Next Topic:Eclipselink nosql with MongoDB Atlas
Goto Forum:
  


Current Time: Fri Apr 26 15:51:37 GMT 2024

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

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

Back to the top