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

public abstract Query<T> join(String path)Adds an inner join on a relationship path.
public abstract Query<T> leftJoin(String path)Adds a left join before the path is used in predicates.
public abstract Query<T> fetch(String field)Initializes a direct relationship for returned entities, overriding lazy mapping.
public abstract Query<T> containsElement(String field, Object value)Adds a scalar collection membership predicate without loading the collection.
public abstract Query<T> eq(String field, Object value)Adds an equality predicate; null matches SQL NULL.
public abstract Query<T> ne(String field, Object value)Adds an inequality predicate; null matches SQL IS NOT NULL.
public abstract Query<T> gt(String field, Object value)Adds a greater-than predicate.
public abstract Query<T> ge(String field, Object value)Adds a greater-than-or-equal predicate.
public abstract Query<T> lt(String field, Object value)Adds a less-than predicate.
public abstract Query<T> le(String field, Object value)Adds a less-than-or-equal predicate.
public abstract Query<T> like(String field, String pattern)Adds a SQL LIKE predicate.
public abstract Query<T> isNull(String field)Adds an IS NULL predicate.
public abstract Query<T> isNotNull(String field)Adds an IS NOT NULL predicate.
public abstract Query<T> in(String field, Object... values)Adds an IN predicate; an empty array matches no rows.
public abstract Query<T> orderBy(String field, boolean ascending)Appends an ordering term.
public abstract Query<T> limit(int value)Sets the maximum number of results; zero returns no rows.
public abstract Query<T> offset(int value)Sets the number of leading results to skip.
public abstract List<T> list()Executes the query, applying pagination and fetch requests.
public abstract T first()Executes the query for at most one result, respecting the offset.
public abstract long count()Counts matching root entities, ignoring ordering and pagination.

Method details

join

public abstract Query<T> join(String path)
Adds an inner join on a relationship path.

Parameters

path String
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

path String
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

field String
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

field String
Java element-collection name
value Object
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

field String
Java attribute name or joined path
value Object
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

field String
Java attribute name or joined path
value Object
bound comparison value

Returns

this query

gt

public abstract Query<T> gt(String field, Object value)
Adds a greater-than predicate.

Parameters

field String
Java attribute name or joined path
value Object
bound comparison value

Returns

this query

ge

public abstract Query<T> ge(String field, Object value)
Adds a greater-than-or-equal predicate.

Parameters

field String
Java attribute name or joined path
value Object
bound comparison value

Returns

this query

lt

public abstract Query<T> lt(String field, Object value)
Adds a less-than predicate.

Parameters

field String
Java attribute name or joined path
value Object
bound comparison value

Returns

this query

le

public abstract Query<T> le(String field, Object value)
Adds a less-than-or-equal predicate.

Parameters

field String
Java attribute name or joined path
value Object
bound comparison value

Returns

this query

like

public abstract Query<T> like(String field, String pattern)
Adds a SQL LIKE predicate.

Parameters

field String
Java string attribute name or joined path
pattern String
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

field String
Java attribute name or joined path

Returns

this query

isNotNull

public abstract Query<T> isNotNull(String field)
Adds an IS NOT NULL predicate.

Parameters

field String
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

field String
Java attribute name or joined path
values Object...
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

field String
Java attribute name or joined path
ascending boolean
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

value int
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

value int
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