Interface SynchronizeableQuery

  • All Known Subinterfaces:
    NativeQuery<T>, NativeQueryImplementor<R>, ProcedureCall, ProcedureCallImplementor<R>
    All Known Implementing Classes:
    NativeQueryImpl, ProcedureCallImpl

    public interface SynchronizeableQuery
    Represents the abstract notion of a query whose results are affected by the data stored in a given set of named query spaces. A query space is usually, but not always, a relational database table, in which case the name of the space is simply the table name.

    Each entity type or collection is understood to store its state in one or more query spaces. Usually, the query spaces are automatically determined by the mapping, but sometimes they must be specified explicitly using @Synchronize.

    Query spaces mediate the interaction between query execution and synchronization of in-memory state with the database:

    • When auto-flush is enabled, in-memory changes to every dirty entity whose state belongs to any query space which affects a given query must be flushed before the query is executed.
    • Conversely, when changes to an entity whose state is stored in a given query space are flushed to the database, every cached query result set for a query affected by that query space must be immediately invalidated.

    Typically, query spaces are independent (non-overlapping), and Hibernate always treats them as such. Overlapping or hierarchical query spaces are in principle meaningful, but any such relationship between query spaces is the responsibility of the client.

    A query space name is not always a table name. In principle, it's permitted to be any arbitrary string which uniquely identifies an abstract location where state is stored persistently. It's even possible that the data in a single table is segmented in such a way that the table is effectively the union of multiple independent query spaces.

    See Also:
    Synchronize, HibernateHints.HINT_NATIVE_SPACES
    • Method Detail

      • getSynchronizedQuerySpaces

        Collection<String> getSynchronizedQuerySpaces()
        Obtain the list of query spaces this query is synchronized with.
        Returns:
        The list of query spaces upon which the query is synchronized.
      • addSynchronizedQuerySpace

        SynchronizeableQuery addSynchronizedQuerySpace​(String querySpace)
        Add a query space. The effect of this call is to:
        • force an auto-flush if any entity associated with the current session and mapped to the given query space has pending changes which have not yet been synchronized with the database, and
        • if the result set of this query is cached, mark it for invalidation when any entity mapped to the given query space is synchronized with the database in any session.
        Parameters:
        querySpace - The name of the query space, usually the name of a database table.
        Returns:
        this, for method chaining