Program: 64738
Project: 64738
Buggy source:
public void testPessimisticLock() throws InterruptedException {
  if ((JUnitTestCase.getServerSession()).getPlatform().isHANA()) {
    return;
  }
  if (isOnServer() || !isSelectForUpateSupported()) {
    return;
  }
  EntityManager em=createEntityManager();
  try {
    Query query=em.createQuery("String_Node_Str");
    query.setParameter("String_Node_Str","String_Node_Str");
    Employee bob=(Employee)query.getSingleResult();
    final int bobId=bob.getId();
    clearCache();
    em.clear();
    query=em.createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",bobId);
    query.setHint(QueryHints.PESSIMISTIC_LOCK,PessimisticLock.Lock);
    beginTransaction(em);
    bob=(Employee)query.getSingleResult();
    final EntityManager em2=createEntityManager();
    try {
      Runnable runnable=new Runnable(){
        public void run(){
          try {
            beginTransaction(em2);
            Query query2=em2.createQuery("String_Node_Str");
            query2.setParameter("String_Node_Str",bobId);
            query2.setHint(QueryHints.PESSIMISTIC_LOCK_TIMEOUT,10);
            Employee emp=(Employee)query2.getSingleResult();
            emp.setFirstName("String_Node_Str");
            commitTransaction(em2);
          }
 catch (          javax.persistence.RollbackException ex) {
            if (ex.getMessage().indexOf("String_Node_Str") == -1) {
              ex.printStackTrace();
              fail("String_Node_Str" + ex);
            }
          }
        }
      }
;
      Thread t2=new Thread(runnable);
      t2.start();
      Thread.sleep(1000);
      em.refresh(bob);
      assertTrue("String_Node_Str","String_Node_Str".equals(bob.getFirstName()));
      rollbackTransaction(em);
      t2.join();
    }
  finally {
      if (isTransactionActive(em2)) {
        rollbackTransaction(em2);
      }
      closeEntityManager(em2);
    }
  }
  finally {
    if (isTransactionActive(em)) {
      rollbackTransaction(em);
    }
    closeEntityManager(em);
  }
}

Fixed version (ground truth):
public void testPessimisticLock() throws InterruptedException {
  if ((JUnitTestCase.getServerSession()).getPlatform().isHANA()) {
    return;
  }
  if (isOnServer() || !isSelectForUpateSupported()) {
    return;
  }
  EntityManager em=createEntityManager();
  try {
    Query query=em.createQuery("String_Node_Str");
    query.setParameter("String_Node_Str","String_Node_Str");
    Employee bob=(Employee)query.getSingleResult();
    final int bobId=bob.getId();
    clearCache();
    em.clear();
    query=em.createQuery("String_Node_Str");
    query.setParameter("String_Node_Str",bobId);
    query.setHint(QueryHints.PESSIMISTIC_LOCK,PessimisticLock.Lock);
    beginTransaction(em);
    bob=(Employee)query.getSingleResult();
    final EntityManager em2=createEntityManager();
    try {
      Runnable runnable=new Runnable(){
        @Override public void run(){
          try {
            beginTransaction(em2);
            Query query2=em2.createQuery("String_Node_Str");
            query2.setParameter("String_Node_Str",bobId);
            query2.setHint(QueryHints.PESSIMISTIC_LOCK_TIMEOUT,10);
            Employee emp=(Employee)query2.getSingleResult();
            emp.setFirstName("String_Node_Str");
            commitTransaction(em2);
          }
 catch (          javax.persistence.RollbackException ex) {
            if (ex.getMessage().indexOf("String_Node_Str") == -1) {
              ex.printStackTrace();
              fail("String_Node_Str" + ex);
            }
          }
        }
      }
;
      Thread t2=new Thread(runnable);
      t2.start();
      Thread.sleep(1000);
      em.refresh(bob);
      assertTrue("String_Node_Str","String_Node_Str".equals(bob.getFirstName()));
      rollbackTransaction(em);
      t2.join();
    }
  finally {
      if (isTransactionActive(em2)) {
        rollbackTransaction(em2);
      }
      closeEntityManager(em2);
    }
  }
  finally {
    if (isTransactionActive(em)) {
      rollbackTransaction(em);
    }
    closeEntityManager(em);
  }
}