javax.persistence.QueryHint Java Examples

The following examples show how to use javax.persistence.QueryHint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateXAnnotations.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public XAnnotation<javax.persistence.NamedQuery> createNamedQuery(
		NamedQuery source) {
	return source == null ? null :
	//
			new XAnnotation<javax.persistence.NamedQuery>(
					javax.persistence.NamedQuery.class,
					//
					AnnotationUtils.create("query", source.getQuery()),
					//
					AnnotationUtils.create("hints",
							createQueryHint(source.getHint()),
							QueryHint.class),
					//
					AnnotationUtils.create("name", source.getName()),
					AnnotationUtils.create("lockMode",
							createLockMode(source.getLockMode()))

			//
			);

}
 
Example #2
Source File: PostRepository.java    From POC with Apache License 2.0 6 votes vote down vote up
@Query("SELECT distinct p FROM Post p LEFT JOIN FETCH p.tags pt LEFT JOIN FETCH pt.tag JOIN p.details where p in :posts")
@QueryHints(@QueryHint(name = org.hibernate.jpa.QueryHints.HINT_PASS_DISTINCT_THROUGH, value = "false"))
List<Post> findPostsWithAllDetails(@Param("posts") List<Post> postList);
 
Example #3
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void buildQueryHints(List<Element> elements, AnnotationDescriptor ann){
	List<QueryHint> queryHints = new ArrayList<>( elements.size() );
	for ( Element hint : elements ) {
		AnnotationDescriptor hintDescriptor = new AnnotationDescriptor( QueryHint.class );
		String value = hint.attributeValue( "name" );
		if ( value == null ) {
			throw new AnnotationException( "<hint> without name. " + SCHEMA_VALIDATION );
		}
		hintDescriptor.setValue( "name", value );
		value = hint.attributeValue( "value" );
		if ( value == null ) {
			throw new AnnotationException( "<hint> without value. " + SCHEMA_VALIDATION );
		}
		hintDescriptor.setValue( "value", value );
		queryHints.add( AnnotationFactory.create( hintDescriptor ) );
	}
	ann.setValue( "hints", queryHints.toArray( new QueryHint[queryHints.size()] ) );
}
 
Example #4
Source File: CdiQueryInvocationContext.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public Query applyRestrictions(Query query)
{
    Parameters params = getParams();
    Method method = getMethod();
    
    if (params.hasSizeRestriction())
    {
        query.setMaxResults(params.getSizeRestriciton());
    }
    
    if (params.hasFirstResult())
    {
        query.setFirstResult(params.getFirstResult());
    }
    
    LockModeType lockMode = extractLockMode();
    if (lockMode != null)
    {
        query.setLockMode(lockMode);
    }
    
    QueryHint[] hints = extractQueryHints();
    if (hints != null)
    {
        for (QueryHint hint : hints)
        {
            query.setHint(hint.name(), hint.value());
        }
    }

    applyEntityGraph(query, method);
    query = applyJpaQueryPostProcessors(query);
    return query;
}
 
Example #5
Source File: QuestionRepository.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
@Query("select q from Question q where q.id in :questionIds")
@QueryHints(value = { @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH_TYPE, value = "IN"),
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "q.questionOptions"),
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "q.subquestions"),
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "q.translations"),
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "questionOptions.translations"),
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "subquestions.translations"),
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "subquestions.questionOptions"), }, forCounting = false)
List<Question> findInList(@Param("questionIds")
List<Integer> questionIds);
 
Example #6
Source File: CdiQueryInvocationContext.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private QueryHint[] extractQueryHints()
{
    org.apache.deltaspike.data.api.Query query = getRepositoryMethodMetadata().getQuery();        
    if (query != null && query.hints().length > 0)
    {
        return query.hints();
    }

    return null;
}
 
Example #7
Source File: CachingJpaRepository.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
@QueryHints(@QueryHint(name = CACHEABLE, value = "true"))
List<T> findAll();
 
Example #8
Source File: CachingJpaRepository.java    From stream-registry with Apache License 2.0 4 votes vote down vote up
@QueryHints(@QueryHint(name = CACHEABLE, value = "true"))
List<T> findAllById(Iterable<ID> ids);
 
Example #9
Source File: CachingJpaRepository.java    From stream-registry with Apache License 2.0 4 votes vote down vote up
@QueryHints(@QueryHint(name = CACHEABLE, value = "true"))
<S extends T> List<S> findAll(Example<S> example);
 
Example #10
Source File: CachingJpaRepository.java    From stream-registry with Apache License 2.0 4 votes vote down vote up
@QueryHints(@QueryHint(name = CACHEABLE, value = "true"))
boolean existsById(ID id);
 
Example #11
Source File: DictionaryRepository.java    From dpCms with Apache License 2.0 4 votes vote down vote up
@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
public List<Dictionary> findByType(int type);
 
Example #12
Source File: PostRepository.java    From POC with Apache License 2.0 4 votes vote down vote up
@Query("SELECT distinct p FROM Post p LEFT JOIN FETCH p.comments JOIN FETCH p.details d where d.createdBy = :user")
@QueryHints(@QueryHint(name = org.hibernate.jpa.QueryHints.HINT_PASS_DISTINCT_THROUGH, value = "false"))
List<Post> findByDetailsCreatedBy(@Param("user") String userName);
 
Example #13
Source File: CachingJpaRepository.java    From stream-registry with Apache License 2.0 4 votes vote down vote up
@QueryHints(@QueryHint(name = CACHEABLE, value = "true"))
Optional<T> findById(ID id);
 
Example #14
Source File: CarRepository.java    From spring-examples with GNU General Public License v3.0 4 votes vote down vote up
@QueryHints({@QueryHint(name = "org.hibernate.cacheable", value = "true")})
List<Car> findAll();
 
Example #15
Source File: RunningExecutionPlanRepository.java    From score with Apache License 2.0 4 votes vote down vote up
@Query("from RunningExecutionPlan r where r.flowUUID = :flowUUID")
@QueryHints({@QueryHint(name = "org.hibernate.cacheable", value = "true")})
public List<RunningExecutionPlan> findByUuidCached(@Param("flowUUID") String flowUUID);
 
Example #16
Source File: SimpleIntermediateRepository.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Query(hints = {
        @QueryHint(name = "openjpa.hint.OptimizeResultCount", value = "some.invalid.value"),
        @QueryHint(name = "org.hibernate.comment", value = "I'm a little comment short and stout")
})
Simple findBy(Long id);
 
Example #17
Source File: UserRepository.java    From spring-boot with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve users by their lastname. The finder {@literal User.findByLastname} is declared in
 * {@literal META-INF/orm.xml} .
 *
 * @param lastname
 * @return all users with the given lastname
 */
@QueryHints({@QueryHint(name = "foo", value = "bar")})
List<User> findByLastname(String lastname);
 
Example #18
Source File: SysOrgElementRepository.java    From mPaaS with Apache License 2.0 2 votes vote down vote up
/**
 * 获取组织架构层级关系(用于更新组织架构层级关系)
 *
 * @param tenantId
 * @return
 */
@QueryHints({@QueryHint(name = "org.hibernate.cacheable", value = "true")})
@Query("select s.fdId, p.fdId, p.fdHierarchyId, p.fdParentOrg.fdId, p.fdOrgType, p.fdTreeLevel from SysOrgElement s inner join s.fdParent p where s.fdOrgType > 1 and s.fdOrgType < 16 and s.fdIsAvailable = true and s.fdTenantId = :tenantId and (p.fdOrgType = 1 and (s.fdParentOrg is null or s.fdParentOrg <> p) or p.fdOrgType > 1 and (s.fdParentOrg is null and p.fdParentOrg is not null or s.fdParentOrg is not null and p.fdParentOrg is null or s.fdParentOrg <> p.fdParentOrg) or s.fdHierarchyId <> concat(concat(p.fdHierarchyId, s.fdId), 'x'))")
List<Object[]> findElementRelation(@Param("tenantId") int tenantId);
 
Example #19
Source File: SysOrgGroupRepository.java    From mPaaS with Apache License 2.0 2 votes vote down vote up
/**
 * 获取群组关联关系
 *
 * @param tenantId
 * @return
 */
@QueryHints({@QueryHint(name = "org.hibernate.cacheable", value = "true")})
@Query(value = "select fd_group_id, fd_element_id from sys_org_group_element left join sys_org_element on fd_element_id = fd_id where fd_org_type = 16 and fd_tenant_id = :tenantId", nativeQuery = true)
List<String[]> loadManyToMany(@Param("tenantId") int tenantId);