-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: org.hibernate.exception.LockAcquisitionException:
PostPosted: Wed Sep 16, 2015 12:04 pm 
Newbie

Joined: Wed Sep 16, 2015 11:40 am
Posts: 3
I have @version annotation in bean (POJO) class as below and created a version column in database to achieve optimistic locking.

Code:
@Version
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}


and also session.lock for the same entity to achieve pessimistic locking.

Code:
Sequence SequenceObj = (Sequence) session.get(
            Sequence.class, ID);
    session.lock(SequenceObj, LockMode.FORCE);
    criteria.add(Restrictions.eq("sequenceName", "Some Name"));
    criteria.add(Restrictions.eq("sequence",existingId));

    SequenceObj.setSequence(existingId);
    session.update(capeSequenceObj);
    session.flush();
    return existingId;


I am getting org.hibernate.exception.LockAcquisitionException: could not retrieve version: for entity exception and transaction getting rolled back. Can I use both(@version annotation for optimistic locking and session.lock for pessimistic locking) for same entity? if so how?

I have also tried only optimistic locking through @ Version (commented session.lock(SequenceObj, LockMode.FORCE);)but getting org.hibernate.exception.LockAcquisitionException: could not update the object.

The problem is in clustered (multi-node) environment, in single node it is working fine.

So finally I have tried optimistic locking and pessimistic locking at first go and later tried with only optimistic locking but none of the approach worked. Please throw some light as I am not expert in this area.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.