使用 DropWizard Hibernate 进行单元测试时显示“当前没有会话绑定到执行上下文”

2024-05-03

我将 DW 与 Hibernate 结合使用,并尝试为我的 DAO 编写单元测试。我的代码基于这个例子 https://github.com/dropwizard/dropwizard/blob/1310d7c981581b4e1be97104f5bb34c3a8e68ee9/dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/UnitOfWorkAwareProxyFactoryTest.java。很遗憾,getCurrentSession()总是抛出,即使是在调用之后立即抛出sessionFactory.openSession():

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

My setUp与他们的几乎相同(除了 JDBC 驱动程序和 URL)。有什么明显的我做错了吗?我需要设置吗current_session_context_class也许吧,如果是的话,怎么办?我没有使用配置文件。也许我应该是?

我想我可以创建我的SessionFactory more 像这样 https://github.com/dropwizard/dropwizard/blob/6fcfe910ec2e3491fe66bc0263334de8489c71b7/dropwizard-testing/src/main/java/io/dropwizard/testing/common/DAOTest.java#L98,但这不是我认为的 DropWizard 方式。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 DropWizard Hibernate 进行单元测试时显示“当前没有会话绑定到执行上下文” 的相关文章

随机推荐