目前没有会话绑定到执行上下文 [英] No session currently bound to execution context

查看:336
本文介绍了目前没有会话绑定到执行上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 session.getCurrentSession()时,我得到了以下异常。





  hibernate.current_session_context_class:managed 

org.hibernate.HibernateException:没有会话当前绑定到执行上下文
在org.hibernate.context.internal.ManagedSessionContext.currentSession(ManagedSessionContext.java:75)
在org.hibernate。 internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
at io.dropwizard.hibernate.AbstractDAO.currentSession(AbstractDAO.java:36)
at io.dropwizard.hibernate.AbstractDAO.persist(AbstractDAO。 java:149)

我用dropwizard使用它。谁能帮我解决这个问题?

您需要为您的Resource方法添加 @UnitOfWork 注释。 dropwizard手册, hibernate章节


I got below exception when I used session.getCurrentSession().

I have mentioned

hibernate.current_session_context_class: managed

org.hibernate.HibernateException: No session currently bound to execution context
    at org.hibernate.context.internal.ManagedSessionContext.currentSession(ManagedSessionContext.java:75)
    at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
    at io.dropwizard.hibernate.AbstractDAO.currentSession(AbstractDAO.java:36)
    at io.dropwizard.hibernate.AbstractDAO.persist(AbstractDAO.java:149)

I use this with dropwizard. Can anyone help me to solve this ?

解决方案

If you are using Dropwizard Hibernate. You need to add @UnitOfWork annotation to your Resource method. More info within dropwizard manual, hibernate chapter.

这篇关于目前没有会话绑定到执行上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆