[英]Updating the same table on the different applications using hibernate
I have 2 nodes of application and both of them updates the same db table.我有 2 个应用程序节点,它们都更新同一个数据库表。 However, updated columns are different.
但是,更新的列是不同的。 In here the problem occurs and secondly running application updates the whole row instead single column.
在这里出现问题,然后运行应用程序更新整行而不是单列。 Let's deep dive into problem explanation.
让我们深入研究问题解释。
The table name is "student" and it has 3 columns.表名是“student”,它有 3 列。 Assuming ID, column1,column2
假设 ID,column1,column2
initial state of the row is ID=1, column1="abc", column2="xyz" The problematic scenario steps are below行的初始 state 为 ID=1, column1="abc", column2="xyz"有问题的场景步骤如下
Finally, App-instances override the each other' s columns.最后,应用实例覆盖彼此的列。 I want to see the final row as column1="ABC", column2="XYZ" .
我想将最后一行视为column1="ABC", column2="XYZ" 。 However, it is column1="abc", column2="XYZ" .
但是,它是column1="abc", column2="XYZ" 。
My question is that why App-instance-1 updates the column2 even if no changes on the column2.我的问题是,为什么 App-instance-1 会更新 column2,即使 column2 没有更改。 column2 is not dirty on the instance-1.
column2 在 instance-1 上不脏。 How can i overcome this issue?
我该如何克服这个问题?
@Entity
@Table("student")
public class Student {
private Long ID;
private String column1;
private String column2;
// Assuming other definations are ok.
}
Thanks in advance.提前致谢。
As far as my knowledge goes you could try one of those 2 methods:据我所知,您可以尝试以下两种方法之一:
@Version
provided by Hibernate)@Version
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.