【发布时间】:2018-06-07 07:46:55
【问题描述】:
我有一个在 3.6 上运行的旧项目。我刚刚更新到 Hibernate 5,我有几个不再运行的测试。
例子:
@Test
public void testConflictingKeyword() {
Location loc = locationDao.findByKeyword("l1");
try {
loc.setKeyword("l2");
locationDao.update(loc);
fail("should not be able to update entity, another entity with keyword exists");
} catch (Exception e) {}
}
此测试在 3.6 上运行良好。我可以看到调用了 dao 更新,并且我得到了一个 constrantviolationexception。
但是,升级到 5 之后,update 方法就不再调用了。
但是,如果我在更新后添加另一个locationDao.findByKeyword("l1") 方法调用,则会执行更新sql!
我怀疑它与自动提交和刷新有关,但我不确定在哪里查看并使 5 的行为与 3.6 中一样...
如果有人能提供一些线索,我将不胜感激。
【问题讨论】:
-
您是否在更新方法中调用了 flush()?
-
不,我没有。它一直有效,所以我没有看到任何需要。
-
你能用hibernate 4测试它吗?只是为了弄清楚他们在哪些方面改变了您的问题?
标签: java hibernate hibernate-mapping