3

I have the following Entity structure:


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....

}

the concrete Entity:



@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 ....

}

Now, I select from the database an entity of MyEntity type, lock it with entityManager.lock(myEntityInstance, LockModeType.OPTIMISTIC);, modify it, and persist modifications. The thing that I expect to get is to have oplock column's value incremented (oplock is the version column), but it is untouched.

Question: Does it behave right or am I missing something? I think the right behavior would be that the oplock's value would be incremented.


Edit: After I switched from hibernate 3.6 to hibernate 4.1, I still get the same behavior.

4

1 回答 1

1

Finally I solved my problem:

I put only @MappedSuperclass annotation above BaseEntity class. For more details you can read here.

于 2012-11-19T12:47:31.617 回答