0

So I am trying to implement the pessimistic lock in one of my POJO class and I have tried all the different methods mentioned in this.

This is in my controller:

@Transactional
public ModelAndView getList(Model model){

    SGroup sGroup = maintainSGroupService.findGroupByID();
    return new ModelAndView("th_List");
}

This is in my service class:

public SGroup findSGroupByID() {
    SGroup group = null;
    try {
        group = submissionGroupRepository.findByObjectID(anObjectID);
    }catch (Exception he) {
        logger.error("Caught HibernateException in findSGroupByID().", he);
    }
    return group;
 }

This is in my repository class:

 @Lock(LockModeType.PESSIMISTIC_WRITE)
 public SubmissionGroup findByObjectID(Long id);

I don't get any exception or anything But the problem is when I login from another id I am still able to access the same record. I should be getting PessimisticLockoutException. Is there anything I am missing?

FigureCodeOut
  • 79
  • 1
  • 11
  • Possible duplicate of [How to enable LockModeType.PESSIMISTIC\_WRITE when looking up entities with Spring Data JPA?](https://stackoverflow.com/questions/16159396/how-to-enable-lockmodetype-pessimistic-write-when-looking-up-entities-with-sprin) – K.Nicholas Nov 02 '18 at 23:10
  • @K.Nicholas - We have tried that way as well , thing is we are trying to access the same record by opening two different tabs but it doesn't throw any kind of exception as it is supposed to do. Quite unsure on what is missing. – FigureCodeOut Nov 05 '18 at 16:54

0 Answers0