繁体   English   中英

使用JPA(Hibernate)不会增加版本列

[英]version column does not get increased with JPA (Hibernate)

我有以下实体结构:


public abstract class BaseEntity {

    private int _version;

    public BaseEntity() {
    }

    @Version
    @Column(name = "oplock", nullable = false)
    private int getVersion() {
        return _version;
    }

    @SuppressWarnings("unused")
    private void setVersion(final int version) {
        _version = version;
    }
    //some other code goes here....

}

具体实体:



@Table(name="my_table", schema="public", 
    uniqueConstraints=@UniqueConstraint(columnNames={"username", "attribute"})
)
public class MyEntity extends BaseEntity implements java.io.Serializable {

    private int id;
    private String username;
    private String attribute;
    private String op;
    private String value;

    public MyEntity() {
    }
    //some code goes here ....

}

现在,我从数据库中选择一个MyEntity类型的实体,用entityManager.lock(myEntityInstance, LockModeType.OPTIMISTIC);锁定它entityManager.lock(myEntityInstance, LockModeType.OPTIMISTIC); ,修改它,并坚持修改。 我期望获得的是使oplock列的值递增( oplock是版本列),但它不受影响。

问题:它表现得正确还是我错过了什么? 我认为正确的行为是oplock的值会增加。


编辑:从hibernate 3.6切换到hibernate 4.1后,我仍然得到相同的行为。

最后我解决了我的问题:

我只将@MappedSuperclass注释放在BaseEntity类之上。 有关详细信息,请阅读此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM