Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-1602

Query with lock mode set to PESSIMISTIC_WRITE does not have for update clause attached to the sql when runs twice

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.0.0
    • 2.0.0
    • jdbc
    • None

    Description

      The following test case executes query two times.

      The sql generated for the first time:
      sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?) optimize for 1 row FOR READ ONLY WITH RR USE AND KEEP UPDATE LOCKS

      The sql generated for the second time:
      sql = SELECT t0.KEYNAME, t0.KEYVAL FROM KEYGEN t0 WHERE (t0.KEYNAME = ?)

      public void testKeyGen() {
      EntityManager em = emf.createEntityManager();
      KeyGenEntity key = null;
      em.getTransaction().begin();
      for (int i = 0;i < 2; i++) {
      Query q = em.createNamedQuery("getStationKeyForUpdate");
      q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
      q.setParameter("keyname", keyName);
      try

      { key = (KeyGenEntity) q.getSingleResult(); em.refresh(key); }

      catch (NoResultException e)

      { // No keys found for this name - create a new one int keyVal = 0; key = new KeyGenEntity(keyName, keyVal); em.persist(key); em.lock(key, LockModeType.PESSIMISTIC_WRITE); }

      int keyVal = key.getKeyval();
      key.setKeyval(keyVal + 1);
      }
      em.getTransaction().commit();
      }

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            ppoddar@apache.org Pinaki Poddar
            faywang Fay Wang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment