Interface Query<T>

Type Parameters:
T - mapped entity type

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.
  • Method Summary

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

    • join

      Query<T> join(String path)
      Adds an inner join on a relationship path.
      Parameters:
      path - Java relationship path
      Returns:
      this query
    • leftJoin

      Query<T> leftJoin(String path)
      Adds a left join before the path is used in predicates.
      Parameters:
      path - Java relationship path
      Returns:
      this query
    • fetch

      Query<T> fetch(String field)
      Initializes a direct relationship for returned entities, overriding lazy mapping.
      Parameters:
      field - Java relationship name
      Returns:
      this query
    • containsElement

      Query<T> containsElement(String field, Object value)
      Adds a scalar collection membership predicate without loading the collection.
      Parameters:
      field - Java element-collection name
      value - element to match; null matches SQL NULL
      Returns:
      this query
    • eq

      Query<T> eq(String field, Object value)
      Adds an equality predicate; null matches SQL NULL.
      Parameters:
      field - Java attribute name or joined path
      value - bound comparison value
      Returns:
      this query
    • ne

      Query<T> ne(String field, Object value)
      Adds an inequality predicate; null matches SQL IS NOT NULL.
      Parameters:
      field - Java attribute name or joined path
      value - bound comparison value
      Returns:
      this query
    • gt

      Query<T> gt(String field, Object value)
      Adds a greater-than predicate.
      Parameters:
      field - Java attribute name or joined path
      value - bound comparison value
      Returns:
      this query
    • ge

      Query<T> ge(String field, Object value)
      Adds a greater-than-or-equal predicate.
      Parameters:
      field - Java attribute name or joined path
      value - bound comparison value
      Returns:
      this query
    • lt

      Query<T> lt(String field, Object value)
      Adds a less-than predicate.
      Parameters:
      field - Java attribute name or joined path
      value - bound comparison value
      Returns:
      this query
    • le

      Query<T> le(String field, Object value)
      Adds a less-than-or-equal predicate.
      Parameters:
      field - Java attribute name or joined path
      value - bound comparison value
      Returns:
      this query
    • like

      Query<T> like(String field, String pattern)
      Adds a SQL LIKE predicate.
      Parameters:
      field - Java string attribute name or joined path
      pattern - bound SQL pattern; percent and underscore are wildcards
      Returns:
      this query
    • isNull

      Query<T> isNull(String field)
      Adds an IS NULL predicate.
      Parameters:
      field - Java attribute name or joined path
      Returns:
      this query
    • isNotNull

      Query<T> isNotNull(String field)
      Adds an IS NOT NULL predicate.
      Parameters:
      field - Java attribute name or joined path
      Returns:
      this query
    • in

      Query<T> in(String field, Object... values)
      Adds an IN predicate; an empty array matches no rows.
      Parameters:
      field - Java attribute name or joined path
      values - values bound as parameters
      Returns:
      this query
    • orderBy

      Query<T> orderBy(String field, boolean ascending)
      Appends an ordering term. Collection joins require ordering by root fields.
      Parameters:
      field - Java attribute name or joined path
      ascending - true for ascending order, false for descending
      Returns:
      this query
    • limit

      Query<T> limit(int value)
      Sets the maximum number of results; zero returns no rows.
      Parameters:
      value - nonnegative result limit
      Returns:
      this query
      Throws:
      IllegalArgumentException - if value is negative
    • offset

      Query<T> offset(int value)
      Sets the number of leading results to skip.
      Parameters:
      value - nonnegative result offset
      Returns:
      this query
      Throws:
      IllegalArgumentException - if value is negative
    • list

      List<T> list()
      Executes the query, applying pagination and fetch requests.
      Returns:
      managed entities matching all predicates
    • first

      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

      long count()
      Counts matching root entities, ignoring ordering and pagination.
      Returns:
      number of distinct matching entities