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

时间:2012-04-02 20:34:52

标签: hibernate

我有一些Hibernate错误,可能很容易解决,但我无法弄清楚。我正在使用Spring& Hibernate& MS SQL。 我有一个Employee对象A,我从列表中选择编辑它。如果我在一个选项卡中打开Employee A,那么我是否在另一个选项卡中打开Employee B.如果我在B仍处于打开状态时提交员工A,则将数据从A保存到B中 - 覆盖B. 我看过我的Equals& amp; Hashcode和我有一个Version列,甚至试图搞乱SQL的隔离级别。我还是没弄明白。这成为一个主要问题,因为用户通常会同时打开两个员工,以便从一个员工复制到另一个员工。我不使用注释并使用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" />

1 个答案:

答案 0 :(得分:0)

虽然你的问题有点模糊,但猜测是你的webapp使用cookie来存储标识符并根据cookie中的值将字段更新提交给字段。也就是说,打开A(cookie设置为A.Id),编辑A,在新标签中打开B(cookie到B.Id),编辑B,保存A(错误的cookie ID!)然后A.values - &gt; B.values。
不过只是一个不知情的猜测。