javax.persistence.TransactionRequiredException: no transaction is in progress
10,975
You need to begin and commit a Hibernate transaction using session factory in each of your service methods or use AOP (Aspect Oriented Programming) for automatic starting,commit/rollback of transactions for you methods. Please refer this.
Related videos on Youtube
Author by
Claudio Pomo
Updated on June 04, 2022Comments
-
Claudio Pomo almost 2 years
I've a service that store many objects into DB with HQL. But I've this exception
javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:789) at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365) at $Proxy42.flush(Unknown Source) at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) at $Proxy42.flush(Unknown Source) at org.skyway.spring.util.dao.AbstractJpaDao.flush(AbstractJpaDao.java:90) at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy52.flush(Unknown Source).........
May be the problem is a lot of number of concurrent operations active on DB. Any suggestions?
-
Claudio Pomo almost 12 yearsall my methods have '@transactional' annotation
-
vikas almost 12 yearsok, but problem is definitely because of transaction not being attached. Do you have <tx:annotation-driven/> in your spring beans context?
-
Claudio Pomo almost 12 yearsyes:
<tx:annotation-driven transaction-manager="transactionManager"/>
-
Claudio Pomo almost 12 yearsbeginning everything works, but I get the exception after a few successes
-
vikas almost 12 yearsare you using at least JDK 5? What implementation you are using for transactionManager?
-
Claudio Pomo almost 12 yearsUse the latest version of java, and atomikos for transactionManager
-
vikas over 11 years@ClaudioPomo Although, you have accepted my answer, I am curious what was the exact error because you said that you were already following all my suggestions.