Package org.hibernate

Interface IdentifierLoadAccess<T>

  • All Known Implementing Classes:

    public interface IdentifierLoadAccess<T>
    Loads an entity by its primary identifier.

    The interface is especially useful when customizing association fetching using an EntityGraph.

     var graph = session.createEntityGraph(Book.class);
     Book book =

    It's also useful for loading entity instances with a specific cache interaction mode in effect, or in read-only mode.

     Book book =
    See Also:
    • Method Detail

      • with

        IdentifierLoadAccess<T> with​(CacheMode cacheMode)
        Specify the CacheMode to use when obtaining an entity.
        cacheMode - The CacheMode to use
        this, for method chaining
      • withFetchGraph

        default IdentifierLoadAccess<T> withFetchGraph​(RootGraph<T> graph)
        Override the associations fetched by default by specifying the complete list of associations to be fetched as an entity graph.
      • getReference

        T getReference​(Object id)
        Return the persistent instance with the given identifier, assuming that the instance exists. This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed.

        You should not use this method to determine if an instance exists; to check for existence, use load(java.lang.Object) instead. Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.

        id - The identifier for which to obtain a reference
        the persistent instance or proxy
      • load

        T load​(Object id)
        Return the persistent instance with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return that instance, initializing it if needed. This method never returns an uninitialized instance.
        id - The identifier
        The persistent instance or null