Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Transactions not working in junit with eclipselink(Transactions not working in junit with eclipselink)
Transactions not working in junit with eclipselink [message #1858051] Mon, 13 March 2023 12:41 Go to next message
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
We are working on Migration of Toplink to Eclipselink in our project.

We are extending base Junit class with AbstractTransactionalDataSourceSpringContextTests class from spring 2.0 in our existing Project which has many convenient methods to handle transactions(end transaction,start transaction).

So Same class I am trying to use to test the transactions after migrating to eclipselink but the transactions are not getting committed. The reason I can see from debug is TransactionStatus does not hold the object that needs to be persisted. I have highlighted the UnitOfWork which gets changed while executing the query and committing the transaction in Eclipsselink_UOW.PNG .

I have also tried with @Transactional annotation and AbstractTransactionalJUnit4SpringContextTests from spring 5 but I can see transactions are not getting committed.

FYI:

In 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.Staaten</class>
<class>group.id.domain.ClientsystemeImpl</class>-->
<class>de.bund.bamf.InGe.bo.impl.StaatenImpl</class>
<exclude-unlisted-classes />
<shared-cache-mode>NONE</shared-cache-mode><!-- true</exclude-unlisted-classes> -->
<properties>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@****" />
<property name="javax.persistence.jdbc.user" value="***" />
<property name="javax.persistence.jdbc.password" value="***" />
<!-- EclipseLink should create the database schema automatically -->
<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.cache.shared.default" value="true"/>-->
</properties>
</persistence-unit>
</persistence>


And for transaction manager in springxml:

<?xml version="1.0" encoding="windows-1252"?> <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


<context:component-scan base-package="org.example"/> <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.SQLServerPlatform"/>
</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>-->

</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven proxy-target-class="true"
transaction-manager="transactionManager" />

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value="${}" />
<property name="password" value="${}" />
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="${*}" />
</bean>

</beans>


Am I missing any property to set ? Or is there any other way to be tested for eclipselink Could you please help me out on this as I am struct here to progress further?
Re: Transactions not working in junit with eclipselink [message #1858053 is a reply to message #1858051] Mon, 13 March 2023 13:24 Go to previous messageGo to next message
Radek Felcman is currently offline Radek FelcmanFriend
Messages: 19
Registered: March 2021
Junior Member
I can't say so much about
org.springframework.*
classes but in the EclipseLink You can check
https://github.com/eclipse-ee4j/eclipselink/tree/master/jpa/eclipselink.jpa.spring.test
https://github.com/eclipse-ee4j/eclipselink/tree/master/jpa/eclipselink.jpa.spring.test/src/it/resources
Re: Transactions not working in junit with eclipselink [message #1858066 is a reply to message #1858053] Tue, 14 March 2023 09:31 Go to previous message
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
Hi Radek,

In my Test cacses if i use entitymanager.getTransaction.commit(),
I can see the data gets persisted but i want to use the methods from AbstractTransactionalDataSourceSpringContextTests
to commit the transactions.
Previous Topic:Find managed entities in PersistenceContext
Next Topic:Spring Transactions with ecliplink jpa
Goto Forum:
  


Current Time: Fri Apr 26 20:45:28 GMT 2024

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

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

Back to the top