【发布时间】:2013-08-27 09:28:00
【问题描述】:
以下是表结构
公式
余额 = 原始金额 + 余额(以前)
50=50+0 ID(1)
200=150+50 ID(2)
关于第二行,我们如何使用休眠更新余额但从其他表中选择。
In HQL, only the INSERT INTO … SELECT … is supported; there is no INSERT INTO … VALUES. HQL only support insert from another table. [source]
如果使用休眠,I first get the balance of max id of customer 1 和 then pass the balance to the new object 就可以了!
但在多用户环境中,为one user get the balance of max id of customer 1,同时other user insert the new row and update the balance。那么第一个获得余额的用户是老because when first user transaction geting the balance other user insert new row and update balance。在这种情况下,第一个用户交易相对于他在更新第二个用户交易之前获得的先前余额插入了错误的余额。
hibernate 有公告功能来控制这种情况吗?
我们如何使用 hibernate session.save() 以最新余额保存交易。 ?
更新我!
【问题讨论】:
-
hibernate应该如何知道第2行对第1行的依赖关系?
标签: java sql hibernate api save