public interface Query<T>
A mutable, parameterized query obtained from
Session.query(Class).
Uses Java attribute names and joins relationship paths as needed. Predicates are
combined with AND. Execution flushes pending changes in an active transaction.
Keep the owning session open; queries are not thread-safe. Applications should
not implement this interface.Type parameters
<T>- mapped entity type
Methods
Method details
join
public abstract Query<T> join(String path)Adds an inner join on a relationship path.
Parameters
pathString- Java relationship path
Returns
this query
leftJoin
public abstract Query<T> leftJoin(String path)Adds a left join before the path is used in predicates.
Parameters
pathString- Java relationship path
Returns
this query
fetch
public abstract Query<T> fetch(String field)Initializes a direct relationship for returned entities, overriding lazy mapping.
Parameters
fieldString- Java relationship name
Returns
this query
containsElement
public abstract Query<T> containsElement(String field, Object value)Adds a scalar collection membership predicate without loading the collection.
Parameters
fieldString- Java element-collection name
valueObject- element to match; null matches SQL NULL
Returns
this query
eq
public abstract Query<T> eq(String field, Object value)Adds an equality predicate; null matches SQL NULL.
Parameters
fieldString- Java attribute name or joined path
valueObject- bound comparison value
Returns
this query
ne
public abstract Query<T> ne(String field, Object value)Adds an inequality predicate; null matches SQL IS NOT NULL.
Parameters
fieldString- Java attribute name or joined path
valueObject- bound comparison value
Returns
this query
gt
public abstract Query<T> gt(String field, Object value)Adds a greater-than predicate.
Parameters
fieldString- Java attribute name or joined path
valueObject- bound comparison value
Returns
this query
ge
public abstract Query<T> ge(String field, Object value)Adds a greater-than-or-equal predicate.
Parameters
fieldString- Java attribute name or joined path
valueObject- bound comparison value
Returns
this query
lt
public abstract Query<T> lt(String field, Object value)Adds a less-than predicate.
Parameters
fieldString- Java attribute name or joined path
valueObject- bound comparison value
Returns
this query
le
public abstract Query<T> le(String field, Object value)Adds a less-than-or-equal predicate.
Parameters
fieldString- Java attribute name or joined path
valueObject- bound comparison value
Returns
this query
like
public abstract Query<T> like(String field, String pattern)Adds a SQL LIKE predicate.
Parameters
fieldString- Java string attribute name or joined path
patternString- bound SQL pattern; percent and underscore are wildcards
Returns
this query
isNull
public abstract Query<T> isNull(String field)Adds an IS NULL predicate.
Parameters
fieldString- Java attribute name or joined path
Returns
this query
isNotNull
public abstract Query<T> isNotNull(String field)Adds an IS NOT NULL predicate.
Parameters
fieldString- Java attribute name or joined path
Returns
this query
in
public abstract Query<T> in(String field, Object... values)Adds an IN predicate; an empty array matches no rows.
Parameters
fieldString- Java attribute name or joined path
valuesObject...- values bound as parameters
Returns
this query
orderBy
public abstract Query<T> orderBy(String field, boolean ascending)Appends an ordering term. Collection joins require ordering by root fields.
Parameters
fieldString- Java attribute name or joined path
ascendingboolean- true for ascending order, false for descending
Returns
this query
limit
public abstract Query<T> limit(int value)Sets the maximum number of results; zero returns no rows.
Parameters
valueint- nonnegative result limit
Returns
this query
Throws
IllegalArgumentException- if value is negative
offset
public abstract Query<T> offset(int value)Sets the number of leading results to skip.
Parameters
valueint- nonnegative result offset
Returns
this query
Throws
IllegalArgumentException- if value is negative
list
public abstract List<T> list()Executes the query, applying pagination and fetch requests.
Returns
managed entities matching all predicates
first
public abstract T first()Executes the query for at most one result, respecting the offset.
Returns
the first managed entity, or null if no match or the limit is zero
count
public abstract long count()Counts matching root entities, ignoring ordering and pagination.
Returns
number of distinct matching entities