No session currently bound to execution context

风流意气都作罢 提交于 2019-12-04 00:20:12
yunspace

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

Can you try with : session.openSession() - It tell hibernate to always opens a new session and you have to close once you are done with the operations. With session.getCurrentSession(), hibernate returns a session bound to a context that you don't need to close and only need to set the hibernate.current_session_context_class to thread.

You can also configure session with SpringSessionContext, if your application is Spring based.

Edit your hibernate-cfg.xml with below line:

hibernate.current_session_context_class=org.springframework.orm.hibernate3.SpringSessionContext

What above line will do?

Making session context class as "org.springframework.orm.hibernate3.SpringSessionContext ", Hibernate will assume it is executing inside of a Spring transactional context (i.e. through a Spring transactional aspect) and Spring will now manage your transaction for you. However if you call getCurrentSession() outside of such a context, Hibernate will throw an exception complaining that no Session is bound to the thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!