“No session currently bound to execution context” in unit test with DropWizard Hibernate

試著忘記壹切 提交于 2020-08-10 03:38:31

问题


I'm using DW with Hibernate, and trying to write a unit test for my DAO. I've based my code off this example. Unfortunately, getCurrentSession() always throws, even immediately after a call tosessionFactory.openSession():

sessionFactory.openSession();
sessionFactory.getCurrentSession(); 
// throws org.hibernate.HibernateException: No session currently bound to execution context

My setUp is almost identical to theirs (except for the JDBC driver and URL). Is there something obvious I'm doing wrong? Do I need to set current_session_context_class perhaps, and if so, how? I'm not using a configuration file. Maybe I should be?

I suppose I could create my SessionFactory more like this, but that's not the DropWizard way I think.

来源:https://stackoverflow.com/questions/63292887/no-session-currently-bound-to-execution-context-in-unit-test-with-dropwizard-h

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