【发布时间】:2017-04-19 14:46:23
【问题描述】:
我正在使用 hibernate,想知道当多个用户请求到来时,hibernate 是如何处理的。
@Transactional 在数据层方法上。
User user = new User();
user.setCreatedBy("TestSad");
user.setUsername("TestSadd");
Integer id = (Integer) this.sessionFactory.getCurrentSession().save(user);
// put the debug point here
int i = 1;
if( i ==1 ){
// intentionally i was throwing exception as i dont want to save
throw new NumberFormatException();
}
对于我的测试,我打开了一个浏览器 chrome 并点击了事务,我得到的 id 值增加了 1 到 db 中存在的值。我没有关闭调试点。说 id = 10 之后,我又打开了一个浏览器 firefox 并点击了事务,我得到的 id 值加一到我在使用 chrome 浏览器调试期间得到的值。说 id = 11
下一个场景。 我已经重新启动了服务器。 再次继续上述步骤,我每次都将值增加一。说 id 12。
因此,它真正好的休眠以这种方式工作以避免出现问题。 我已经通过谷歌论坛了解它是如何工作的,但没有得到它。是hibernate如何在内部处理ACID。 有人可以帮助我理解它。只是想知道。
【问题讨论】:
-
或者查看answer。