Package com.querydsl.jpa.impl
Class AbstractJPAQuery<T,Q extends AbstractJPAQuery<T,Q>>
java.lang.Object
com.querydsl.core.support.QueryBase<Q>
com.querydsl.core.support.FetchableQueryBase<T,Q>
com.querydsl.core.support.FetchableSubQueryBase<T,Q>
com.querydsl.jpa.JPAQueryBase<T,Q>
com.querydsl.jpa.impl.AbstractJPAQuery<T,Q>
- Type Parameters:
T- result typeQ- concrete subtype
- All Implemented Interfaces:
Fetchable<T>,FetchableQuery<T,,JPQLQuery<T>> FilteredClause<JPQLQuery<T>>,Query<JPQLQuery<T>>,SimpleQuery<JPQLQuery<T>>,ExtendedSubQuery<T>,Expression<T>,SubQueryExpression<T>,JPQLQuery<T>,Serializable
- Direct Known Subclasses:
JPAQuery
Abstract base class for JPA API based implementations of the JPQLQuery interface
- Author:
- tiwe
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final javax.persistence.EntityManagerprotected @Nullable javax.persistence.FlushModeTypeprotected @Nullable javax.persistence.LockModeTypeprotected @Nullable FactoryExpression<?>protected final QueryHandlerFields inherited from class com.querydsl.jpa.JPAQueryBase
queryMixinFields inherited from class com.querydsl.core.support.QueryBase
MDC_PARAMETERS, MDC_QUERY -
Constructor Summary
ConstructorsConstructorDescriptionAbstractJPAQuery(javax.persistence.EntityManager em) AbstractJPAQuery(javax.persistence.EntityManager em, JPQLTemplates templates, QueryMetadata metadata) -
Method Summary
Modifier and TypeMethodDescriptionclone()Clone the state of this query to a new instanceabstract Qclone(javax.persistence.EntityManager entityManager) Clone the state of this query to a new instance with the given EntityManagerabstract Qclone(javax.persistence.EntityManager entityManager, JPQLTemplates templates) Clone the state of this query to a new instance with the given EntityManager and the specified templatesprotected voidjavax.persistence.QueryExpose the original JPA query for the given projectionprotected javax.persistence.QuerycreateQuery(@Nullable QueryModifiers modifiers, boolean forCount) protected JPQLSerializerfetch()longDeprecated.fetchOne()Deprecated.fetchResultsrequires a count query to be computed.com.mysema.commons.lang.CloseableIterator<T>iterate()protected voidprotected voidreset()setFlushMode(javax.persistence.FlushModeType flushMode) setLockMode(javax.persistence.LockModeType lockMode) stream()Methods inherited from class com.querydsl.jpa.JPAQueryBase
fetchAll, fetchJoin, from, from, from, getTemplates, innerJoin, innerJoin, innerJoin, innerJoin, innerJoin, innerJoin, join, join, join, join, join, join, leftJoin, leftJoin, leftJoin, leftJoin, leftJoin, leftJoin, on, on, rightJoin, rightJoin, rightJoin, rightJoin, rightJoin, rightJoin, serialize, serialize, toStringMethods inherited from class com.querydsl.core.support.FetchableSubQueryBase
accept, contains, contains, eq, eq, exists, getMetadata, getType, goe, goe, gt, gt, hashCode, in, in, isNotNull, isNull, loe, loe, lt, lt, ne, ne, notExistsMethods inherited from class com.querydsl.core.support.FetchableQueryBase
equals, fetchFirst, transform, uniqueResultMethods inherited from class com.querydsl.core.support.QueryBase
distinct, groupBy, groupBy, having, having, limit, offset, orderBy, orderBy, restrict, set, where, whereMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.querydsl.core.types.Expression
accept, getTypeMethods inherited from interface com.querydsl.core.support.ExtendedSubQuery
contains, contains, eq, eq, exists, goe, goe, gt, gt, in, in, isNotNull, isNull, loe, loe, lt, lt, ne, ne, notExistsMethods inherited from interface com.querydsl.core.Fetchable
fetchFirstMethods inherited from interface com.querydsl.core.FetchableQuery
transformMethods inherited from interface com.querydsl.core.FilteredClause
whereMethods inherited from interface com.querydsl.core.SimpleQuery
distinct, limit, offset, orderBy, restrict, setMethods inherited from interface com.querydsl.core.types.SubQueryExpression
getMetadata
-
Field Details
-
hints
-
entityManager
protected final javax.persistence.EntityManager entityManager -
queryHandler
-
lockMode
@Nullable protected @Nullable javax.persistence.LockModeType lockMode -
flushMode
@Nullable protected @Nullable javax.persistence.FlushModeType flushMode -
projection
-
-
Constructor Details
-
AbstractJPAQuery
public AbstractJPAQuery(javax.persistence.EntityManager em) -
AbstractJPAQuery
public AbstractJPAQuery(javax.persistence.EntityManager em, JPQLTemplates templates, QueryMetadata metadata)
-
-
Method Details
-
fetchCount
Deprecated.fetchCountrequires a count query to be computed. Inquerydsl-sql, this is done by wrapping the query in a subquery, like so:SELECT COUNT(*) FROM (<original query>). Unfortunately, JPQL - the query language of JPA - does not allow queries to project from subqueries. As a result there isn't a universal way to express count queries in JPQL. Historically QueryDSL attempts at producing a modified query to compute the number of results instead. However, this approach only works for simple queries. Specifically queries with multiple group by clauses and queries with a having clause turn out to be problematic. This is becauseCOUNT(DISTINCT a, b, c), while valid SQL in most dialects, is not valid JPQL. Furthermore, a having clause may refer select elements or aggregate functions and therefore cannot be emulated by moving the predicate to the where clause instead. In order to supportfetchCountfor queries with multiple group by elements or a having clause, we generate the count in memory instead. This means that the method simply falls back to returning the size offetch(). For large result sets this may come at a severe performance penalty. For very specific domain models wherefetchCount()has to be used in conjunction with complex queries containing multiple group by elements and/or a having clause, we recommend using the Blaze-Persistence integration for QueryDSL. Among other advanced query features, Blaze-Persistence makes it possible to select from subqueries in JPQL. As a result theBlazeJPAQueryprovided with the integration, implementsfetchCountproperly and always executes a proper count query. -
createQuery
public javax.persistence.Query createQuery()Expose the original JPA query for the given projection- Returns:
- query
-
createQuery
protected javax.persistence.Query createQuery(@Nullable @Nullable QueryModifiers modifiers, boolean forCount) -
iterate
-
stream
-
fetch
- Specified by:
fetchin interfaceFetchable<T>- Overrides:
fetchin classFetchableQueryBase<T,Q extends AbstractJPAQuery<T, Q>>
-
fetchResults
Deprecated.fetchResultsrequires a count query to be computed. Inquerydsl-sql, this is done by wrapping the query in a subquery, like so:SELECT COUNT(*) FROM (<original query>). Unfortunately, JPQL - the query language of JPA - does not allow queries to project from subqueries. As a result there isn't a universal way to express count queries in JPQL. Historically QueryDSL attempts at producing a modified query to compute the number of results instead. However, this approach only works for simple queries. Specifically queries with multiple group by clauses and queries with a having clause turn out to be problematic. This is becauseCOUNT(DISTINCT a, b, c), while valid SQL in most dialects, is not valid JPQL. Furthermore, a having clause may refer select elements or aggregate functions and therefore cannot be emulated by moving the predicate to the where clause instead. In order to supportfetchResultsfor queries with multiple group by elements or a having clause, we generate the count in memory instead. This means that the method simply falls back to returning the size offetch(). For large result sets this may come at a severe performance penalty. For very specific domain models wherefetchResults()has to be used in conjunction with complex queries containing multiple group by elements and/or a having clause, we recommend using the Blaze-Persistence integration for QueryDSL. Among other advanced query features, Blaze-Persistence makes it possible to select from subqueries in JPQL. As a result theBlazeJPAQueryprovided with the integration, implementsfetchResultsproperly and always executes a proper count query. Mind that for any scenario where the count is not strictly needed separately, we recommend to usefetch()instead. -
logQuery
-
reset
protected void reset()- Specified by:
resetin classJPAQueryBase<T,Q extends AbstractJPAQuery<T, Q>>
-
fetchOne
- Throws:
NonUniqueResultException
-
setLockMode
-
setFlushMode
-
setHint
-
createSerializer
- Specified by:
createSerializerin classJPAQueryBase<T,Q extends AbstractJPAQuery<T, Q>>
-
clone
-
clone
Clone the state of this query to a new instance with the given EntityManager- Parameters:
entityManager- entity manager- Returns:
- cloned query
-
clone
Clone the state of this query to a new instance with the given EntityManager and the specified templates- Parameters:
entityManager- entity managertemplates- templates- Returns:
- cloned query
-
clone
Clone the state of this query to a new instance- Specified by:
clonein classJPAQueryBase<T,Q extends AbstractJPAQuery<T, Q>> - Returns:
- cloned query
-
fetchCountrequires a count query to be computed.