Interface Query<R>

    • Method Detail

      • getProducer

        QueryProducer getProducer()
        Get the QueryProducer this Query originates from.
      • uniqueResultOptional

        java.util.Optional<R> uniqueResultOptional()
      • stream

        java.util.stream.Stream<R> stream()
        Retrieve a Stream over the query results.

        In the initial implementation (5.2) this returns a simple sequential Stream. The plan is to return a a smarter stream in 6.x leveraging the SQM model.

        You should call BaseStream.close() after processing the stream so that the underlying resources are deallocated right away.

        Returns:
        The results Stream
        Since:
        5.2
      • setParameter

        Query<R> setParameter​(Parameter<java.time.LocalDateTime> param,
                              java.time.LocalDateTime value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(Parameter<java.time.ZonedDateTime> param,
                              java.time.ZonedDateTime value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(Parameter<java.time.OffsetDateTime> param,
                              java.time.OffsetDateTime value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(java.lang.String name,
                              java.time.Instant value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(java.lang.String name,
                              java.time.LocalDateTime value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(java.lang.String name,
                              java.time.ZonedDateTime value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(java.lang.String name,
                              java.time.OffsetDateTime value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(int position,
                              java.time.Instant value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(int position,
                              java.time.LocalDateTime value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(int position,
                              java.time.ZonedDateTime value,
                              TemporalType temporalType)
      • setParameter

        Query<R> setParameter​(int position,
                              java.time.OffsetDateTime value,
                              TemporalType temporalType)
      • scroll

        ScrollableResults scroll()
        Description copied from interface: Query
        Return the query results as ScrollableResults. The scrollability of the returned results depends upon JDBC driver support for scrollable ResultSets.

        You should call ScrollableResults.close() after processing the ScrollableResults so that the underlying resources are deallocated right away.

        Specified by:
        scroll in interface Query<R>
        Returns:
        the result iterator
        See Also:
        ScrollableResults
      • scroll

        ScrollableResults scroll​(ScrollMode scrollMode)
        Description copied from interface: Query
        Return the query results as ScrollableResults. The scrollability of the returned results depends upon JDBC driver support for scrollable ResultSets.

        You should call ScrollableResults.close() after processing the ScrollableResults so that the underlying resources are deallocated right away.

        Specified by:
        scroll in interface Query<R>
        Parameters:
        scrollMode - The scroll mode
        Returns:
        the result iterator
        See Also:
        ScrollableResults, ScrollMode
      • list

        java.util.List<R> list()
        Description copied from interface: Query
        Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
        Specified by:
        list in interface Query<R>
        Returns:
        the result list
      • uniqueResult

        R uniqueResult()
        Description copied from interface: Query
        Convenience method to return a single instance that matches the query, or null if the query returns no results.
        Specified by:
        uniqueResult in interface Query<R>
        Returns:
        the single result or null
      • getCacheMode

        CacheMode getCacheMode()
        Description copied from interface: Query
        Obtain the CacheMode in effect for this query. By default, the query inherits the CacheMode of the Session from which is originates. NOTE: The CacheMode here only effects reading/writing of the query cache, not the entity/collection caches.
        Specified by:
        getCacheMode in interface BasicQueryContract<R>
        Specified by:
        getCacheMode in interface Query<R>
        Returns:
        The query CacheMode.
        See Also:
        Session.getCacheMode(), CacheMode
      • getCacheRegion

        java.lang.String getCacheRegion()
        Description copied from interface: Query
        Obtain the name of the second level query cache region in which query results will be stored (if they are cached, see the discussion on Query.isCacheable() for more information). null indicates that the default region should be used.
        Specified by:
        getCacheRegion in interface BasicQueryContract<R>
        Specified by:
        getCacheRegion in interface Query<R>
        Returns:
        The specified cache region name into which query results should be placed; null indicates the default region.
      • getFetchSize

        java.lang.Integer getFetchSize()
        Description copied from interface: Query
        Obtain the JDBC fetch size hint in effect for this query. This value is eventually passed along to the JDBC query via Statement.setFetchSize(int). As defined b y JDBC, this value is a hint to the driver to indicate how many rows to fetch from the database when more rows are needed. NOTE : JDBC expressly defines this value as a hint. It may or may not have any effect on the actual query execution and ResultSet processing depending on the driver.
        Specified by:
        getFetchSize in interface BasicQueryContract<R>
        Specified by:
        getFetchSize in interface Query<R>
        Returns:
        The timeout in seconds
        See Also:
        Statement.getFetchSize(), Statement.setFetchSize(int)
      • getLockOptions

        LockOptions getLockOptions()
        Description copied from interface: Query
        Obtains the LockOptions in effect for this query.
        Specified by:
        getLockOptions in interface Query<R>
        Returns:
        The LockOptions
        See Also:
        LockOptions
      • getComment

        java.lang.String getComment()
        Description copied from interface: Query
        Obtain the comment currently associated with this query. Provided SQL commenting is enabled (generally by enabling the hibernate.use_sql_comments config setting), this comment will also be added to the SQL query sent to the database. Often useful for identifying the source of troublesome queries on the database side.
        Specified by:
        getComment in interface Query<R>
        Returns:
        The comment.
      • getQueryString

        java.lang.String getQueryString()
        Description copied from interface: Query
        Get the query string.
        Specified by:
        getQueryString in interface Query<R>
        Returns:
        the query string
      • getParameterMetadata

        ParameterMetadata getParameterMetadata()
        Description copied from interface: Query
        Access to information about query parameters.
        Specified by:
        getParameterMetadata in interface Query<R>
        Returns:
        information about query parameters.
      • setParameter

        Query<R> setParameter​(java.lang.String name,
                              java.lang.Object value)
        Description copied from interface: Query
        Bind a named query parameter using its inferred Type. If the parameter is defined in such a way that the Type cannot be inferred from its usage context then use of this form of binding is not allowed, and Query.setParameter(String, Object, Type) should be used instead
        Specified by:
        setParameter in interface Query
        Specified by:
        setParameter in interface Query<R>
        Specified by:
        setParameter in interface TypedQuery<R>
        Parameters:
        name - the parameter name
        value - the (possibly-null) parameter value
        Returns:
        this, for method chaining
      • setParameter

        Query<R> setParameter​(java.lang.String name,
                              java.lang.Object val,
                              Type type)
        Description copied from interface: Query
        Bind a named query parameter using the supplied Type
        Specified by:
        setParameter in interface Query<R>
        Parameters:
        name - the name of the parameter
        val - the possibly-null parameter value
        type - the Hibernate type
        Returns:
        this, for method chaining
      • setParameter

        Query<R> setParameter​(int position,
                              java.lang.Object value)
        Description copied from interface: Query
        Bind a positional query parameter using its inferred Type. If the parameter is defined in such a way that the Type cannot be inferred from its usage context then use of this form of binding is not allowed, and Query.setParameter(int, Object, Type) should be used instead
        Specified by:
        setParameter in interface Query
        Specified by:
        setParameter in interface Query<R>
        Specified by:
        setParameter in interface TypedQuery<R>
        Parameters:
        position - the position of the parameter in the query string, numbered from 0.
        value - the possibly-null parameter value
        Returns:
        this, for method chaining
      • setParameter

        <T> Query<R> setParameter​(QueryParameter<T> parameter,
                                  T val)
        Description copied from interface: Query
        Bind a query parameter using its inferred Type. If the parameter is defined in such a way that the Type cannot be inferred from its usage context then use of this form of binding is not allowed, and Query.setParameter(QueryParameter, Object, Type) should be used instead
        Specified by:
        setParameter in interface Query<R>
        Parameters:
        parameter - The query parameter memento
        val - the possibly-null parameter value
        Returns:
        this, for method chaining
      • setParameter

        <P> Query<R> setParameter​(int position,
                                  P val,
                                  TemporalType temporalType)
        Description copied from interface: Query
        Bind a positional query parameter as some form of date/time using the indicated temporal-type.
        Specified by:
        setParameter in interface Query<R>
        Parameters:
        position - the position of the parameter in the query string, numbered from 0.
        val - the possibly-null parameter value
        temporalType - the temporal-type to use in binding the date/time
        Returns:
        this, for method chaining
      • setParameter

        <P> Query<R> setParameter​(QueryParameter<P> parameter,
                                  P val,
                                  Type type)
        Description copied from interface: Query
        Bind a query parameter using the supplied Type
        Specified by:
        setParameter in interface Query<R>
        Parameters:
        parameter - The query parameter memento
        val - the possibly-null parameter value
        type - the Hibernate type
        Returns:
        this, for method chaining
      • setParameter

        Query<R> setParameter​(int position,
                              java.lang.Object val,
                              Type type)
        Description copied from interface: Query
        Bind a value to a JDBC-style query parameter.
        Specified by:
        setParameter in interface Query<R>
        Parameters:
        position - the position of the parameter in the query string, numbered from 0.
        val - the possibly-null parameter value
        type - the Hibernate type
        Returns:
        this, for method chaining
      • setParameter

        <P> Query<R> setParameter​(QueryParameter<P> parameter,
                                  P val,
                                  TemporalType temporalType)
        Description copied from interface: Query
        Bind a query parameter as some form of date/time using the indicated temporal-type.
        Specified by:
        setParameter in interface Query<R>
        Parameters:
        parameter - The query parameter memento
        val - the possibly-null parameter value
        temporalType - the temporal-type to use in binding the date/time
        Returns:
        this, for method chaining
      • setParameter

        <P> Query<R> setParameter​(java.lang.String name,
                                  P val,
                                  TemporalType temporalType)
        Description copied from interface: Query
        Bind a named query parameter as some form of date/time using the indicated temporal-type.
        Specified by:
        setParameter in interface Query<R>
        Parameters:
        name - the parameter name
        val - the possibly-null parameter value
        temporalType - the temporal-type to use in binding the date/time
        Returns:
        this, for method chaining
      • setCacheable

        Query<R> setCacheable​(boolean cacheable)
        Description copied from interface: Query
        Enable/disable second level query (result) caching for this query.
        Specified by:
        setCacheable in interface BasicQueryContract<R>
        Specified by:
        setCacheable in interface Query<R>
        Parameters:
        cacheable - Should the query results be cacheable?
        Returns:
        this, for method chaining
        See Also:
        Query.isCacheable()
      • setCacheRegion

        Query<R> setCacheRegion​(java.lang.String cacheRegion)
        Description copied from interface: Query
        Set the name of the cache region where query results should be cached (if cached at all).
        Specified by:
        setCacheRegion in interface BasicQueryContract<R>
        Specified by:
        setCacheRegion in interface Query<R>
        Parameters:
        cacheRegion - the name of a query cache region, or null to indicate that the default region should be used.
        Returns:
        this, for method chaining
        See Also:
        Query.getCacheRegion()
      • setTimeout

        Query<R> setTimeout​(int timeout)
        Description copied from interface: Query
        Set the query timeout in seconds. NOTE it is important to understand that any value set here is eventually passed directly through to the JDBC Statement which expressly disallows negative values. So negative values should be avoided as a general rule.
        Specified by:
        setTimeout in interface BasicQueryContract<R>
        Specified by:
        setTimeout in interface Query<R>
        Parameters:
        timeout - the timeout in seconds
        Returns:
        this, for method chaining
        See Also:
        Query.getTimeout()
      • setLockMode

        Query<R> setLockMode​(java.lang.String alias,
                             LockMode lockMode)
        Description copied from interface: Query
        Set the LockMode to use for specific alias (as defined in the query's FROM clause). The alias-specific lock modes specified here are added to the query's internal LockOptions. The effect of these alias-specific LockModes is somewhat dependent on the driver/database in use. Generally speaking, for maximum portability, this method should only be used to mark that the rows corresponding to the given alias should be included in pessimistic locking (LockMode.PESSIMISTIC_WRITE).
        Specified by:
        setLockMode in interface Query<R>
        Parameters:
        alias - a query alias, or "this" for a collection filter
        lockMode - The lock mode to apply.
        Returns:
        this, for method chaining
        See Also:
        Query.getLockOptions()
      • setComment

        Query<R> setComment​(java.lang.String comment)
        Description copied from interface: Query
        Set the comment for this query.
        Specified by:
        setComment in interface Query<R>
        Parameters:
        comment - The human-readable comment
        Returns:
        this, for method chaining
        See Also:
        Query.getComment()
      • addQueryHint

        Query<R> addQueryHint​(java.lang.String hint)
        Description copied from interface: Query
        Add a DB query hint to the SQL. These differ from JPA's QueryHint, which is specific to the JPA implementation and ignores DB vendor-specific hints. Instead, these are intended solely for the vendor-specific hints, such as Oracle's optimizers. Multiple query hints are supported; the Dialect will determine concatenation and placement.
        Specified by:
        addQueryHint in interface Query<R>
        Parameters:
        hint - The database specific query hint to add.
      • setParameterList

        <P> Query<R> setParameterList​(QueryParameter<P> parameter,
                                      java.util.Collection<P> values)
        Description copied from interface: Query
        Bind multiple values to a query parameter using its inferred Type. The Hibernate type of the parameter values is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).
        Specified by:
        setParameterList in interface Query<R>
        Parameters:
        parameter - the parameter memento
        values - a collection of values to list
        Returns:
        this, for method chaining
      • setParameterList

        Query<R> setParameterList​(java.lang.String name,
                                  java.util.Collection values)
        Description copied from interface: Query
        Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).
        Specified by:
        setParameterList in interface Query<R>
        Parameters:
        name - the name of the parameter
        values - a collection of values to list
        Returns:
        this, for method chaining
      • setParameterList

        Query<R> setParameterList​(java.lang.String name,
                                  java.util.Collection values,
                                  Type type)
        Description copied from interface: Query
        Bind multiple values to a named query parameter. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).
        Specified by:
        setParameterList in interface Query<R>
        Parameters:
        name - the name of the parameter
        values - a collection of values to list
        type - the Hibernate type of the values
        Returns:
        this, for method chaining
      • setParameterList

        Query<R> setParameterList​(java.lang.String name,
                                  java.lang.Object[] values,
                                  Type type)
        Description copied from interface: Query
        Bind multiple values to a named query parameter. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).
        Specified by:
        setParameterList in interface Query<R>
        Parameters:
        name - the name of the parameter
        values - a collection of values to list
        type - the Hibernate type of the values
        Returns:
        this, for method chaining
      • setParameterList

        Query<R> setParameterList​(java.lang.String name,
                                  java.lang.Object[] values)
        Description copied from interface: Query
        Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the array. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).
        Specified by:
        setParameterList in interface Query<R>
        Parameters:
        name - the name of the parameter
        values - a collection of values to list
        Returns:
        this, for method chaining
      • setProperties

        Query<R> setProperties​(java.lang.Object bean)
        Description copied from interface: Query
        Bind the property values of the given bean to named parameters of the query, matching property names with parameter names and mapping property types to Hibernate types using heuristics.
        Specified by:
        setProperties in interface Query<R>
        Parameters:
        bean - any JavaBean or POJO
        Returns:
        this, for method chaining
      • setProperties

        Query<R> setProperties​(java.util.Map bean)
        Description copied from interface: Query
        Bind the values of the given Map for each named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.
        Specified by:
        setProperties in interface Query<R>
        Parameters:
        bean - a java.util.Map
        Returns:
        this, for method chaining
      • setText

        @Deprecated
        default Query<R> setText​(int position,
                                 java.lang.String val)
        Deprecated.
        Bind a positional String-valued parameter using streaming.
        Specified by:
        setText in interface Query<R>
        Parameters:
        position - The parameter position
        val - The bind value
        Returns:
        this, for method chaining
      • setSerializable

        @Deprecated
        default Query<R> setSerializable​(int position,
                                         java.io.Serializable val)
        Deprecated.
        Bind a positional binary-valued parameter using serialization.
        Specified by:
        setSerializable in interface Query<R>
        Parameters:
        position - The parameter position
        val - The bind value
        Returns:
        this, for method chaining
      • setDate

        @Deprecated
        default Query<R> setDate​(int position,
                                 java.util.Date val)
        Deprecated.
        Bind a positional Date-valued parameter using just the Date portion.
        Specified by:
        setDate in interface Query<R>
        Parameters:
        position - The parameter position
        val - The bind value
        Returns:
        this, for method chaining
      • setTime

        @Deprecated
        default Query<R> setTime​(int position,
                                 java.util.Date val)
        Deprecated.
        Bind a positional Date-valued parameter using just the Time portion.
        Specified by:
        setTime in interface Query<R>
        Parameters:
        position - The parameter position
        val - The bind value
        Returns:
        this, for method chaining
      • setTimestamp

        @Deprecated
        default Query<R> setTimestamp​(int position,
                                      java.util.Date val)
        Deprecated.
        Bind a positional Date-valued parameter using the full Timestamp.
        Specified by:
        setTimestamp in interface Query<R>
        Parameters:
        position - The parameter position
        val - The bind value
        Returns:
        this, for method chaining
      • setCalendar

        @Deprecated
        default Query<R> setCalendar​(int position,
                                     java.util.Calendar val)
        Deprecated.
        Bind a positional Calendar-valued parameter using the full Timestamp portion.
        Specified by:
        setCalendar in interface Query<R>
        Parameters:
        position - The parameter position
        val - The bind value
        Returns:
        this, for method chaining
      • setCalendarDate

        @Deprecated
        default Query<R> setCalendarDate​(int position,
                                         java.util.Calendar val)
        Deprecated.
        Bind a positional Calendar-valued parameter using just the Date portion.
        Specified by:
        setCalendarDate in interface Query<R>
        Parameters:
        position - The parameter position
        val - The bind value
        Returns:
        this, for method chaining
      • setDate

        @Deprecated
        default Query<R> setDate​(java.lang.String name,
                                 java.util.Date val)
        Bind the val (time is truncated) of a given Date object to a named query parameter.
        Specified by:
        setDate in interface Query<R>
        Parameters:
        name - The name of the parameter
        val - The val object
        Returns:
        this, for method chaining
      • setTime

        @Deprecated
        default Query<R> setTime​(java.lang.String name,
                                 java.util.Date val)
        Bind the time (val is truncated) of a given Date object to a named query parameter.
        Specified by:
        setTime in interface Query<R>
        Parameters:
        name - The name of the parameter
        val - The val object
        Returns:
        this, for method chaining
      • setTimestamp

        @Deprecated
        default Query<R> setTimestamp​(java.lang.String name,
                                      java.util.Date value)
        Bind the value and the time of a given Date object to a named query parameter.
        Specified by:
        setTimestamp in interface Query<R>
        Parameters:
        name - The name of the parameter
        value - The value object
        Returns:
        this, for method chaining
      • setResultTransformer

        @Deprecated
        Query<R> setResultTransformer​(ResultTransformer transformer)
        Deprecated.
        (since 5.2)
        Set a strategy for handling the query results. This can be used to change "shape" of the query result.
        Specified by:
        setResultTransformer in interface Query<R>
        Parameters:
        transformer - The transformer to apply
        Returns:
        this (for method chaining)
      • setParameters

        @Deprecated
        default Query<R> setParameters​(java.lang.Object[] values,
                                       Type[] types)
        Deprecated.
        (since 5.2) Bind values individually
        Bind values and types to positional parameters. Allows binding more than one at a time; no real performance impact. The number of elements in each array should match. That is, element number-0 in types array corresponds to element-0 in the values array, etc,
        Specified by:
        setParameters in interface Query<R>
        Parameters:
        types - The types
        values - The values
        Returns:
        this, for method chaining
      • getResultStream

        default java.util.stream.Stream<R> getResultStream()
        JPA 2.2 defines the getResultStream method so to get a Stream from the JDBC ResultSet. Hibernate 5.2 already defines the stream() method, so getResultStream can delegate to it.
        Specified by:
        getResultStream in interface Query
        Specified by:
        getResultStream in interface TypedQuery<R>
        Returns:
        The results Stream
        Since:
        5.2.11