休眠-2个打开的窗口记录覆盖其他



我有一些Hibernate错误,解决起来可能很简单,但我无法解决。我正在使用Spring&休眠&MS-SQL。我有一个Employee对象a,我从列表中选择它进行编辑。如果我在一个选项卡中打开该员工A,那么如果我在另一个选项卡上打开员工B。如果我在B仍处于打开状态时提交员工A,则会将数据从A保存到B中,从而覆盖B。我看过我的Equals&Hashcode和我有一个Version列,甚至试图扰乱SQL的隔离级别。我还没弄明白。这正成为一个主要问题,因为用户经常会同时打开两个Employee,以便从一个复制到另一个。我不使用注释,而是使用java+hbm文件进行映射。这是我的对手&散列码

public boolean equals(Object other) {
    if ((this == other)) {
        return true;
    }
    if (!(other instanceof Employee)) {
        return false;
    }
    Employee castOther = (Employee) other;
    return this.userLogin.equals(castOther.getUserLogin());
}
public int hashCode() {
    return new HashCodeBuilder().append(this.getUserLogin()).toHashCode();
}

这是我在hbm 中的版本声明

<version name="version" column="VERSION" unsaved-value="negative" />

虽然你的问题有点模糊,但你可以猜测你的网络应用程序正在使用cookie来存储标识符,并根据cookie中的值将更新提交到字段。也就是说,打开A(cookie设置为A.Id),编辑A,在新选项卡中打开B(cookie为B.Id),然后编辑B,保存A(cookie Id错误!),然后A.值->B.值。
不过,这只是一个不知情的猜测。