code: @Nullable
      public final PrintJobStatusExtImpl get(final String id, final boolean lock) {
          final CriteriaBuilder builder = getSession().getCriteriaBuilder();
          final CriteriaQuery<PrintJobStatusExtImpl> criteria =
                  builder.createQuery(PrintJobStatusExtImpl.class);
          final Root<PrintJobStatusExtImpl> root = criteria.from(PrintJobStatusExtImpl.class);
          root.alias("pj");
          root.fetch("result", JoinType.LEFT);
          criteria.where(builder.equal(root.get("referenceId"), id));
          final Query<PrintJobStatusExtImpl> query = getSession().createQuery(criteria);
          if (lock) {
              //LOCK means SELECT FOR UPDATE which prevents these records to be pulled by different
              // instances
              query.setLockMode("pj", LockMode.PESSIMISTIC_READ);
          } else {
              query.setReadOnly(true);  // make sure the object is not updated if there is no lock
          }
          return query.uniqueResult();
      }
docs: Get Job Record.
  
  @param id the id
  @param lock whether record should be locked for transaction
  @return the job status or null.