No session currently bound to execution context

Srinivas picture Srinivas · May 13, 2015 · Viewed 12.5k times · Source

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?

Answer

yunspace picture yunspace · May 14, 2015

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