简体   繁体   中英

Hibernate Optimistic Lock method

I have an entity :

@Entity
public class Client {
  .....

    @Version
    @Column(name="OPTLOCK")
    private long version;
}

Now Optimistic lock is always working, now each method can throw a ObjectStaleStateException BUT, if I want to make Optimistic just some certain method how can I do that ? I have 10 methods in my Service that use my Client entity, but I want to make Optimistic just one method from 10.

What I understand from your question is, you want the locking feature to be used for specific service method.

As far as I know this is not possible.

If you go for pessimist locking you can explicitly pass lock mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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