Hibernate Optimistic Lock method

118 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.