Reputation: 21
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 :
<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 :
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 :
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!
Upvotes: 2
Views: 2636
Reputation: 3759
I was facing the same problem while migrating to Hibernate 5.2.2 and Spring 4.3.3.
In my code I wasn't necessarily using a @Post construct method but I had the same exception no transaction is in progress when calling a simple Get method from the database.
I found this link on the Spring forum, and at the end of the discussion it was pointed out that the problem happens in some transactions, but not in others.
For my case, when I annotated my transaction with REQUIRED
propagation the problem disappeared (it was SUPPORTS
at th beginning).
Upvotes: 1