@SuppressWarnings({"unchecked"})
 public TypedQuery<X> setLockMode(javax.persistence.LockModeType lockModeType) {
   if (!getEntityManager().isTransactionInProgress()) {
     throw new TransactionRequiredException("no transaction is in progress");
   }
   if (!canApplyLockModes()) {
     throw new IllegalStateException("Not a JPAQL/Criteria query");
   }
   this.jpaLockMode = lockModeType;
   ((org.hibernate.impl.QueryImpl) query)
       .getLockOptions()
       .setLockMode(LockModeTypeHelper.getLockMode(lockModeType));
   return this;
 }
  @Override
  @SuppressWarnings({"deprecation"})
  public TypedQuery<X> setHint(String hintName, Object value) {
    boolean skipped = false;
    try {
      if (HINT_TIMEOUT.equals(hintName)) {
        applyTimeout(ConfigurationHelper.getInteger(value));
      } else if (SPEC_HINT_TIMEOUT.equals(hintName)) {
        // convert milliseconds to seconds
        int timeout =
            (int) Math.round(ConfigurationHelper.getInteger(value).doubleValue() / 1000.0);
        applyTimeout(timeout);
      } else if (AvailableSettings.LOCK_TIMEOUT.equals(hintName)) {
        applyLockTimeout(ConfigurationHelper.getInteger(value));
      } else if (HINT_COMMENT.equals(hintName)) {
        applyComment((String) value);
      } else if (HINT_FETCH_SIZE.equals(hintName)) {
        applyFetchSize(ConfigurationHelper.getInteger(value));
      } else if (HINT_CACHEABLE.equals(hintName)) {
        applyCacheable(ConfigurationHelper.getBoolean(value));
      } else if (HINT_CACHE_REGION.equals(hintName)) {
        applyCacheRegion((String) value);
      } else if (HINT_READONLY.equals(hintName)) {
        applyReadOnly(ConfigurationHelper.getBoolean(value));
      } else if (HINT_CACHE_MODE.equals(hintName)) {
        applyCacheMode(ConfigurationHelper.getCacheMode(value));
      } else if (HINT_FLUSH_MODE.equals(hintName)) {
        applyFlushMode(ConfigurationHelper.getFlushMode(value));
      } else if (AvailableSettings.SHARED_CACHE_RETRIEVE_MODE.equals(hintName)) {
        final CacheRetrieveMode retrieveMode = (CacheRetrieveMode) value;

        CacheStoreMode storeMode =
            hints != null
                ? (CacheStoreMode) hints.get(AvailableSettings.SHARED_CACHE_STORE_MODE)
                : null;
        if (storeMode == null) {
          storeMode =
              (CacheStoreMode)
                  entityManager.getProperties().get(AvailableSettings.SHARED_CACHE_STORE_MODE);
        }
        applyCacheMode(CacheModeHelper.interpretCacheMode(storeMode, retrieveMode));
      } else if (AvailableSettings.SHARED_CACHE_STORE_MODE.equals(hintName)) {
        final CacheStoreMode storeMode = (CacheStoreMode) value;

        CacheRetrieveMode retrieveMode =
            hints != null
                ? (CacheRetrieveMode) hints.get(AvailableSettings.SHARED_CACHE_RETRIEVE_MODE)
                : null;
        if (retrieveMode == null) {
          retrieveMode =
              (CacheRetrieveMode)
                  entityManager.getProperties().get(AvailableSettings.SHARED_CACHE_RETRIEVE_MODE);
        }
        applyCacheMode(CacheModeHelper.interpretCacheMode(storeMode, retrieveMode));
      } else if (hintName.startsWith(AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE)) {
        if (!canApplyLockModes()) {
          skipped = true;
        } else {
          // extract the alias
          final String alias =
              hintName.substring(AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE.length() + 1);
          // determine the LockMode
          try {
            final LockMode lockMode = LockModeTypeHelper.interpretLockMode(value);
            applyAliasSpecificLockMode(alias, lockMode);
          } catch (Exception e) {
            LOG.unableToDetermineLockModeValue(hintName, value);
            skipped = true;
          }
        }
      } else {
        skipped = true;
        LOG.ignoringUnrecognizedQueryHint(hintName);
      }
    } catch (ClassCastException e) {
      throw new IllegalArgumentException("Value for hint");
    }

    if (!skipped) {
      if (hints == null) {
        hints = new HashMap<String, Object>();
      }
      hints.put(hintName, value);
    }

    return this;
  }
 private static LockMode getLockMode(LockModeType lockMode) {
   return LockModeTypeHelper.getLockMode(lockMode);
 }
 @SuppressWarnings("deprecation")
 private static LockModeType getLockModeType(LockMode lockMode) {
   // TODO check that if we have UPGRADE_NOWAIT we have a timeout of zero?
   return LockModeTypeHelper.getLockModeType(lockMode);
 }