New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: Shared EntityManager proxy insists on actualTransactiveActive flag even with SYNCHRONIZATION_NEVER [SPR-13838] #18411
Comments
Juergen Hoeller commented I suppose you are using Juergen |
Krzysztof Lewandowski commented Yes, exactly. JpaTransactionManager is used. i can work around it like:
But it doesn't seem to be a cleanest solution. Moreover thread locals won't get cleaned unless I add some transaction event listeners. |
Sathishkumar Murugesan commented Hi, I am also facing similar issue. I have upgraded to latest Spring version from 4.1.6.Release to 4.2.4.Release and suddenly all what has functioned smoothly before, now throws the following exception. Exception occurs in SharedEntityManagerCreator.java. In the same method reported by other user. javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:277) ~[na:4.2.4.RELEASE]
at com.sun.proxy.$Proxy51.persist(Unknown Source) ~[na:na] else if (transactionRequiringMethods.contains(method.getName())) {
// We need a transactional target now, according to the JPA spec.
// Otherwise, the operation would get accepted but remain unflushed...
if (target == null || !TransactionSynchronizationManager.isActualTransactionActive()) {
throw new TransactionRequiredException("No EntityManager with actual transaction available " +
"for current thread - cannot reliably process '" + method.getName() + "' call");
}
} Do you have work around for now? I also created issue in Stackoverflow : http://stackoverflow.com/questions/34494754/upgraded-from-spring-4-1-6-to-4-2-4-and-suddenly-getting-transactionrequiredexce with more explanation and code samples |
Krzysztof Lewandowski commented The most dirty one is to manually call
somewhere before you invoke operation that force those checks |
Sathishkumar Murugesan commented Thanks for workaround. For me target == null, so it fails in the first condition not with ActualTransactionActive. EntityManagerFactoryUtils.java else if (!TransactionSynchronizationManager.isSynchronizationActive()) {
// Indicate that we can't obtain a transactional EntityManager.
return null;
} I dont know why it couldn't find the targetEntityManager. But when i switch 4.1.6 it works like charm If I set this in code.. then it works if(!TransactionSynchronizationManager.isSynchronizationActive()){
TransactionSynchronizationManager.initSynchronization();
TransactionSynchronizationManager.setActualTransactionActive(true);
} |
Juergen Hoeller commented If the first condition fails for you there, I assume you're not using Let's sort out any variant of this issue for 4.2.5 in February. Providing an immediate upgrade path from 4.1.x is a key requirement for us. Juergen |
Sathishkumar Murugesan commented I use JPA transaction manager and attached code snippet of my configuration. <bean id="xxxTxManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="xxxEntityManagerFactory" p:dataSource-ref="xxxDataSource"/>
<tx:annotation-driven transaction-manager="xxxTxManager"/>
<bean id="xxxEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceUnitName="xxxHibernatePersistenceUnit"
p:packagesToScan="com.opensolutions"
p:dataSource-ref="xxxDataSource" p:jpaVendorAdapter-ref="hibernateVendor"
p:jpaPropertyMap-ref="jpaPropertyMap" p:persistenceXmlLocation="classpath*:META-INF/xxx-jpa-persistence.xml"/>
<bean id="hibernateVendor"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:showSql="false"/>
<util:map id="jpaPropertyMap">
<entry key="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<entry key="jadira.usertype.databaseZone" value="jvm"/>
<entry key="jadira.usertype.javaZone" value="jvm"/>
</util:map> |
Juergen Hoeller commented I'm not sure how Juergen |
Sathishkumar Murugesan commented I checked it.., EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource(emf); returns null, so else if (!TransactionSynchronizationManager.isSynchronizationActive()) {
// Indicate that we can't obtain a transactional EntityManager.
return null;
} !! !screenshot-1.png|thumbnail! Before i post the message in the queue, when i inspect getResources, I see all the resources. Attached screenshot of the same for reference. It fails only during reply Regards, |
Juergen Hoeller commented This looks like your As far as my current analysis goes, #17834 seems to have caused the regression for Juergen |
Sathishkumar Murugesan commented I tried to put break point in JpaTransactionManager. But code doesnt even go to JpaTransactionManager. JpaTransactionManger class is never invoked. |
Juergen Hoeller commented I've resolved the original issue here through an extra As for the Juergen |
Murali Mohan Rath commented I have raised a related bug at https://jira.spring.io/browse/DATACMNS-803 |
Murali Mohan Rath commented I had another go by building 4.3.0-BUILD-SNAPSHOT locally and it resolves the issue. I guess the snapshots on spring repo are not updated.
|
Juergen Hoeller commented I haven't got around to the 4.2.5 backport yet; I'll make sure to commit it later this week. So the fix simply isn't available in that branch yet. As for the release dates, we always reflect the current plan here: https://jira.spring.io/browse/SPR/?selectedTab=com.atlassian.jira.jira-projects-plugin:roadmap-panel - 4.2.5 is currently scheduled for Feb 18. Juergen |
Paul Zhang commented hello Juergen, just fellow up with "As for the target suddenly being null in some scenarios on 4.x, this seems to be a separate issue not caused by the changes behind #17834. Let's create a separate JIRA issue for that scenario if it remains to be a problem." did you created separate JIRA issue for this one. |
Sathishkumar Murugesan commented As for the target suddenly being null in some scenarios on 4.x, this seems to be a separate issue not caused by the changes behind #17834. Let's create a separate JIRA issue for that scenario if it remains to be a problem. This issue is not still resolved in Spring 4.3.0 also. Exact Scenario is explained by Murali Mohan Rath : I have raised a related bug at https://jira.spring.io/browse/DATACMNS-803 If we invoke JmsTransactionManager first, followed by JPATransactionManager then JPATransactionManager is coming as null. which eventually breaks code. Because of this issue we were not able to migrate from Spring 4.1.6 to any higher Spring Version. |
Krzysztof Lewandowski opened SPR-13838 and commented
If set the transaction synchronization to be SYNCHRONIZATION_NEVER, e.g.:
I get a following exception when trying to save an object using jpa repository:
With that setup
TransactionSynchronizationManager.setActualTransactionActive(status.hasTransaction());
is not called and now SharedEntityManagerCreator requires actual transaction to be active:Affects: 4.2.4
Attachments:
Issue Links:
1 votes, 5 watchers
The text was updated successfully, but these errors were encountered: