code: public void lock(boolean shouldLock) {
          String lastAlias = getLastAlias();
  
          if (shouldLock) {
              if (lastAlias != null) {
                  criteria.setLockMode(lastAlias, LockMode.PESSIMISTIC_WRITE);
              }
              else {
                  criteria.setLockMode(LockMode.PESSIMISTIC_WRITE);
              }
          }
          else {
              if (lastAlias != null) {
                  criteria.setLockMode(lastAlias, LockMode.NONE);
              }
              else {
                  criteria.setLockMode(LockMode.NONE);
              }
          }
      }
docs: Whether a pessimistic lock should be obtained.
  
  @param shouldLock True if it should