开发者

openjpa throws optimisticklockexception

I am trying openjpa and jpa. All I have is one entity class as corresponding table in the database. one of the attributes of the entity is username and corresponding row in the db table has varchar2(20). and in my main method what i tried to persist and instance of the entity with username longer than 20. All I am doing is

em.getTransaction().begin();开发者_Go百科
em.persist(entity); //entity here is the instance with the username longer than 20
em.getTransaction().commit();

I tried this, hoping to get some other kind of exception, but I don't why I am getting optimisticklockexception.

I do not have any locking setting. I mean I am using default values for locking property.

Does anybody know what's happening here?


Not sure why this happens...I have noticed that the OptimisticLockException can be thrown in weird cases...

Adding a version field to your table and entity can often make OpenJPA work better with locking...

In your entity bean add this (also add the column named VERSION to your table):

private Long version;
@Version
@Column(name="VERSION") 
public Long getVersion() {
    return version;
}
public void setVersion(Long version) {
    this.version = version;
}

Hope this helps...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜