org.hibernate.query.Query.setHint()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(235)

本文整理了Java中org.hibernate.query.Query.setHint方法的一些代码示例,展示了Query.setHint的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setHint方法的具体详情如下:
包路径:org.hibernate.query.Query
类名称:Query
方法名:setHint

Query.setHint介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

protected void applyQuerySettingsAndHints(Query query) {
  if ( lockOptions.getLockMode() != LockMode.NONE ) {
    query.setLockMode( getLockMode( lockOptions.getLockMode() ) );
  }
  Object queryTimeout;
  if ( (queryTimeout = getProperties().get( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
    query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
  }
  Object lockTimeout;
  if( (lockTimeout = getProperties().get( JPA_LOCK_TIMEOUT ))!=null){
    query.setHint( JPA_LOCK_TIMEOUT, lockTimeout );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-11726" )
public void testDistinctPassThroughFalse() {
  doInHibernate( this::sessionFactory, session -> {
    sqlStatementInterceptor.getSqlQueries().clear();
    List<Person> persons = session.createQuery(
        "select distinct p from Person p left join fetch p.phones ")
        .setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, false)
        .setMaxResults(5)
        .getResultList();
    assertEquals(1, persons.size());
    String sqlQuery = sqlStatementInterceptor.getSqlQueries().getLast();
    assertFalse(sqlQuery.contains(" distinct "));
  });
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-11726" )
public void testDistinctPassThroughTrue() {
  doInHibernate( this::sessionFactory, session -> {
    sqlStatementInterceptor.getSqlQueries().clear();
    List<Person> persons = session.createQuery(
        "select distinct p from Person p left join fetch p.phones ")
        .setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, true)
        .setMaxResults(5)
        .getResultList();
    assertEquals(1, persons.size());
    String sqlQuery = sqlStatementInterceptor.getSqlQueries().getLast();
    assertTrue(sqlQuery.contains(" distinct "));
  });
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-12075")
public void testCreateQuerySetTimeoutHint() {
  doInHibernate(
      this::sessionFactory, session -> {
        Query query = session.createQuery( QUERY );
        query.setHint( QueryHints.SPEC_HINT_TIMEOUT, 123000 );
        query.executeUpdate();
        try {
          verify( CONNECTION_PROVIDER.getPreparedStatement( QUERY ), times( 1 ) ).setQueryTimeout( 123 );
        }
        catch (SQLException ex) {
          fail( "should not have thrown exception" );
        }
      }
  );
}

代码示例来源:origin: hibernate/hibernate-orm

List<Person> persons = session.createQuery(
  "select distinct p from Person p" )
.setHint( QueryHints.HINT_PASS_DISTINCT_THROUGH, false )
.getResultList();
String sqlQuery = sqlStatementInterceptor.getSqlQueries().getLast();

代码示例来源:origin: dhis2/dhis2-core

/**
 * Creates a Query for given HQL query string. Must specify the return
 * type of the Query variable.
 * @param hql the HQL query.
 * @return a Query instance with return type specified in the Query<Y>
 */
@SuppressWarnings("unchecked")
protected final <V> Query<V> getTypedQuery( String hql )
{
  return getSession()
    .createQuery( hql )
    .setCacheable( cacheable ).setHint( QueryHints.CACHEABLE, cacheable );
}

代码示例来源:origin: dhis2/dhis2-core

/**
 * Creates a Query for given HQL query string. Return type is casted
 * to generic type T of the Store class.
 * @param hql the HQL query.
 * @return a Query instance with return type is the object type T of the store class
 */
@SuppressWarnings("unchecked")
protected final Query<T> getQuery( String hql )
{
  return getSession().createQuery( hql )
    .setCacheable( cacheable ).setHint( QueryHints.CACHEABLE, cacheable );
}

代码示例来源:origin: dhis2/dhis2-core

/**
 * Get executable Typed Query from Criteria Query.
 * Apply cache if needed.
 * @param criteriaQuery
 * @return  executable TypedQuery
 */
public final TypedQuery<T> getExecutableTypedQuery( CriteriaQuery<T> criteriaQuery )
{
  return getSession()
    .createQuery( criteriaQuery )
    .setCacheable( cacheable ).setHint( QueryHints.CACHEABLE, cacheable );
}

代码示例来源:origin: org.hibernate.orm/hibernate-core

protected void applyQuerySettingsAndHints(Query query) {
  if ( lockOptions.getLockMode() != LockMode.NONE ) {
    query.setLockMode( getLockMode( lockOptions.getLockMode() ) );
  }
  Object queryTimeout;
  if ( (queryTimeout = getProperties().get( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
    query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
  }
  Object lockTimeout;
  if( (lockTimeout = getProperties().get( JPA_LOCK_TIMEOUT ))!=null){
    query.setHint( JPA_LOCK_TIMEOUT, lockTimeout );
  }
}

代码示例来源:origin: dhis2/dhis2-core

.setHint( QueryHints.CACHEABLE, parameters.isCacheable( cacheable ) )
.getSingleResult();

相关文章