Hi Guys,
I have a legacy app that used Spring 4.3 with Hibernate 3.6 which I migrated to Spring 5.3 and Hibernate 5.4. I have this piece of code in a abstract ComonHibernateDAOImpl
which is extended in every DAO class I have and serves some common Hibernate tasks.
public abstract class CommonHibernateDAOImpl<ENTITY extends Serializable> extends HibernateDaoSupport implements CommonHibernateDAO<ENTITY> {
@Override
public final List<ENTITY> findAll(final Class<ENTITY> entityClass) {
return getHibernateTemplate().loadAll(entityClass);
}
}
While this code worked perfectly fine in Hibernate 3.6, is stops working in 5.4 with following error:
Caused by: org.springframework.orm.hibernate5.HibernateSystemException: Calling method 'createCriteria' is not valid without an active transaction (Current status: NOT_ACTIVE); nested exception is org.hibernate.HibernateException: Calling method 'createCriteria' is not valid without an active transaction (Current status: NOT_ACTIVE)
at deployment.myApp.war//org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:267)
at deployment.myApp.war//org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:370)
at deployment.myApp.war//org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:334)
at deployment.myApp.war//org.springframework.orm.hibernate5.HibernateTemplate.loadAll(HibernateTemplate.java:519)
at deployment.myApp.war//com.anes.ilogic.common.integration.dao.impl.CommonHibernateDAOImpl.findAll(CommonHibernateDAOImpl.java:233)
at deployment.myApp.war//com.cl.ilogic.core.vs.service.VsValidationServiceImpl.reload(VsValidationServiceImpl.java:245)
at deployment.myApp.war//com.cl.ilogic.core.vs.service.VsValidationServiceImpl.init(VsValidationServiceImpl.java:298)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at deployment.myApp.war//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1930)
at deployment.myApp.war//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1872)
at deployment.myApp.war//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
... 83 more
Caused by: org.hibernate.HibernateException: Calling method 'createCriteria' is not valid without an active transaction (Current status: NOT_ACTIVE)
at deployment.myApp.war//org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:347)
at deployment.myApp.war/jdk.proxy21/jdk.proxy21.$Proxy213.createCriteria(Unknown Source)
at deployment.myApp.war//org.springframework.orm.hibernate5.HibernateTemplate.lambda$loadAll$4(HibernateTemplate.java:520)
at deployment.myApp.war//org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:367)
... 95 more