org.hibernate.hibernateexception-缺少trasnactioninterceptor

ve7v8dk2  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(146)

我正在将我们的系统升级到运行在tomcat9上的spirng5和hibernate5(这里没有spring引导),并发现了springs-hibernateinterceptor的问题。
我有一个自定义过滤器,它扩展了genericfilterbean,从db中获取users实体。用户获取方法是transaction,readonly=true,整个类被创建为springbean。正常情况下,这工作正常,但有时我得到HibernateeException,因为没有事务处于活动状态。当然,我必须重新启动应用程序,直到它工作。
在导入的上下文中,我确实有:

@EnableTransactionManagement(proxyTargetClass = true)

我认为这与过滤器注册顺序有关,但我不知道如何设置过滤器,使hibernatetransaction在它之前。下面是我现在如何在resourceserverconfigureradapter实现上执行此操作:

.addFilterBefore(permissionAuthenticationFilter, BasicAuthenticationFilter.class)

堆栈跟踪:

org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
     at com.fwc.crazycalls.core.db.ClassLoaderSpringSessionContext.currentSession(ClassLoaderSpringSessionContext.java:41)
     at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:721)
     at com.crazycall.commons.dao.GenericDao.getCurrentSession(GenericDao.java:70)
     at com.crazycall.commons.dao.GenericDao.criteria(GenericDao.java:74)
     at com.fwc.crazycalls.core.staff.dao.UserDao.get(UserDao.java:55)
     at com.fwc.crazycalls.core.staff.dao.UserDao$$FastClassBySpringCGLIB$$e4ad180f.invoke(<generated>)
     at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
     at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687)
     at com.fwc.crazycalls.core.staff.dao.UserDao$$EnhancerBySpringCGLIB$$77691a7a.get(<generated>)
     at com.fwc.crazycalls.web.auth.PrincipalFactory.create(PrincipalFactory.java:44)
     at com.fwc.crazycalls.web.PermissionAuthenticationFilter.createAuthentication(PermissionAuthenticationFilter.java:43)
     at com.fwc.crazycalls.web.PermissionAuthenticationFilter.doFilter(PermissionAuthenticationFilter.java:35)

当一切都按预期工作时,这里是stacktrace(对于格式化-调试器转储很抱歉)

currentSession:85, SpringSessionContext {org.springframework.orm.hibernate5}
getCurrentSession:721, SessionFactoryImpl {org.hibernate.internal}
getCurrentSession:70, GenericDao {com.crazycall.commons.dao}
criteria:74, GenericDao {com.crazycall.commons.dao}
get:56, UserDao {com.fwc.crazycalls.core.staff.dao}
invoke:-1, UserDao$$FastClassBySpringCGLIB$$e4ad180f {com.fwc.crazycalls.core.staff.dao}
invoke:218, MethodProxy {org.springframework.cglib.proxy}
invokeJoinpoint:752, CglibAopProxy$CglibMethodInvocation {org.springframework.aop.framework}
proceed:163, ReflectiveMethodInvocation {org.springframework.aop.framework}
proceedWithInvocation:-1, 867338246 {org.springframework.transaction.interceptor.TransactionInterceptor$$Lambda$1305}
invokeWithinTransaction:295, TransactionAspectSupport {org.springframework.transaction.interceptor}
invoke:98, TransactionInterceptor {org.springframework.transaction.interceptor}
proceed:186, ReflectiveMethodInvocation {org.springframework.aop.framework}
intercept:691, CglibAopProxy$DynamicAdvisedInterceptor {org.springframework.aop.framework}
get:-1, UserDao$$EnhancerBySpringCGLIB$$9a5cbe4f {com.fwc.crazycalls.core.staff.dao}
create:44, PrincipalFactory {com.fwc.crazycalls.web.auth}
createAuthentication:43, PermissionAuthenticationFilter {com.fwc.crazycalls.web}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题