-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: no transaction is in progress
PostPosted: Thu Sep 29, 2016 3:43 am 
Newbie

Joined: Wed Sep 28, 2016 1:57 pm
Posts: 1
Hello,

I am facing an issue and I can't seem to find a solution.

I am migrating a project from Hibernate 5.1.1 to 5.2.2 and Spring from 4.1.0 to 4.3.3.

Using weblogic, when I try to deploy my ear I get a TransactionRequiredException: no transaction is in progress.

This happens on a bean that is supposed to make a lot of queries to the database, and the method is annotated @PostConstruct.

It was working fine before, I updated my hibernate configuration according to the migration guide and I can't seem to find the solution.

This is the modified configuration for Hibernate 5.2.2 :

Code:
<prop key="hibernate.transaction.coordinator_class">jta</prop>
<!-- How to produce transaction -->
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform</prop>


This is an extract of the server log :
Code:
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
   at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3428) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
   at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1395) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
   at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1391) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
   at org.springframework.orm.hibernate5.SessionFactoryUtils.flush(SessionFactoryUtils.java:144) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:95) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:932) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:744) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:487) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
   at com.sun.proxy.$Proxy408.findAll(Unknown Source) ~[?:?]


It was working fine before my migration attempt and I suppose it is related to the fact that the bean is initialized but the transaction is closed.

What is strange is that when I debug the method, I am able to get the first few calls to the database but it fails later on.

In both cases I am using :

Code:
getHibernateTemplate().executeWithNativeSession(new HibernateCallback<List<E>>()


Has anyone of you encountered this kind of problem?

I googled days long and I can't find a single answer corresponding to this problem (btw. this also happens on my Junit tests)

Thanks in advance for your help.

Cheers,

Speed.


Last edited by speedsweep on Thu Sep 29, 2016 8:24 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: no transaction is in progress
PostPosted: Thu Sep 29, 2016 5:52 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Since I can see the TransactionInterceptor on your stack trace, it means that Spring has managed to start the transaction. I'd say this is a Spring issue since the TransactionInterceptor does not propagate the transaction further for Hibernate to pick it up.

You might want to ask this question on the Spring forum as well.


Top
 Profile  
 
 Post subject: Re: no transaction is in progress
PostPosted: Wed Nov 09, 2016 3:22 am 
Newbie

Joined: Wed Nov 09, 2016 3:13 am
Posts: 1
Hi,

Had similar issue -- it was caused by several SessionFactory beans in Spring context used along with HibernateTransactionManager (HTM isn't designed to work with several SFs).

When trying to perform operations in sessions of both SFs in a single transaction, error occurs (yet it somehow worked in Hibernate 3.x).

Solutions I see:
1. One of the SFs should not participate in Spring transactions -- create it not via Spring Factory Bean (it configures custom CurrentContext) but via plain Hibernate means (registry builder);
2. Write custom transaction manager to handle both SFs.

HTH


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.