当我使用 session.getCurrentSession()
时出现以下异常。
我已经提到了
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)
我将它与 dropwizard
一起使用。谁能帮我解决这个问题?
最佳答案
如果您使用的是 Dropwizard Hibernate。您需要将 @UnitOfWork
注释添加到您的 Resource 方法。更多信息在 dropwizard manual, hibernate chapter .
https://stackoverflow.com/questions/30212125/