Top Description Methods
org.hibernate

public Interface IdentifierLoadAccess<T>

Known Direct Implementers
org.hibernate.loader.internal.IdentifierLoadAccessImpl
Imports
java.util.Optional, org.hibernate.graph.GraphSemantic, .RootGraph

Loads an entity by its primary identifier.

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

var graph = session.createEntityGraph(Book.class);
graph.addSubgraph(Book_.publisher);
graph.addPluralSubgraph(Book_.authors)
    .addSubgraph(Author_.person);

Book book =
        session.byId(Book.class)
            .withFetchGraph(graph)
            .load(bookId);

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

Book book =
        session.byId(Book.class)
            .with(CacheMode.GET)
            .withReadOnly(true)
            .load(bookId);
Authors
Eric Dalquist, Steve Ebersole
See Also
Session#byId(Class)

Method Summary

Modifier and TypeMethod and Description
public IdentifierLoadAccess<T>
disableFetchProfile(String profileName)

Customize the associations fetched by specifying a fetch profile that should be disabled during this operation.

public IdentifierLoadAccess<T>
enableFetchProfile(String profileName)

Customize the associations fetched by specifying a fetch profile that should be enabled during this operation.

public T

Returns:

the persistent instance or proxy
getReference
(Object
The identifier for which to obtain a reference
id
)

Return the persistent instance with the given identifier, assuming that the instance exists.

public T

Returns:

The persistent instance or null
load
(Object
The identifier
id
)

Return the persistent instance with the given identifier, or null if there is no such persistent instance.

public Optional<T>

Returns:

The persistent instance, if any, as an Optional
loadOptional
(Object
The identifier
id
)

Just like load, except that here an Optional is returned.

public IdentifierLoadAccess<T>

Returns:

this, for method chaining
with
(LockOptions
The lock options to use
lockOptions
)

Specify the lock options to use when querying the database.

public IdentifierLoadAccess<T>

Returns:

this, for method chaining
with
(CacheMode
The CacheMode to use
cacheMode
)

Specify the CacheMode to use when obtaining an entity.

public default IdentifierLoadAccess<T>
with(RootGraph<T> graph)

Deprecated since 6.3. use withLoadGraph
public IdentifierLoadAccess<T>
with(RootGraph<T> graph, GraphSemantic semantic)

Customize the associations fetched by specifying an entity graph, and how it should be interpreted.

public 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.

public default IdentifierLoadAccess<T>
withLoadGraph(RootGraph<T> graph)

Augment the associations fetched by default by specifying a list of additional associations to be fetched as an entity graph.

public IdentifierLoadAccess<T>
withReadOnly(boolean readOnly)

Specify whether the entity should be loaded in read-only mode.

Method Detail

disableFetchProfileback to summary
public IdentifierLoadAccess<T> disableFetchProfile(String profileName)

Customize the associations fetched by specifying a fetch profile that should be disabled during this operation.

This allows the session-level fetch profiles to be temporarily overridden.

Since
6.3
enableFetchProfileback to summary
public IdentifierLoadAccess<T> enableFetchProfile(String profileName)

Customize the associations fetched by specifying a fetch profile that should be enabled during this operation.

This allows the session-level fetch profiles to be temporarily overridden.

Since
6.3
getReferenceback to summary
public 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 instead. Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.

Parameters
id:Object

The identifier for which to obtain a reference

Returns:T

the persistent instance or proxy

loadback to summary
public 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.

Parameters
id:Object

The identifier

Returns:T

The persistent instance or null

loadOptionalback to summary
public Optional<T> loadOptional(Object id)

Just like load, except that here an Optional is returned.

Parameters
id:Object

The identifier

Returns:Optional<T>

The persistent instance, if any, as an Optional

withback to summary
public IdentifierLoadAccess<T> with(LockOptions lockOptions)

Specify the lock options to use when querying the database.

Parameters
lockOptions:LockOptions

The lock options to use

Returns:IdentifierLoadAccess<T>

this, for method chaining

withback to summary
public IdentifierLoadAccess<T> with(CacheMode cacheMode)

Specify the CacheMode to use when obtaining an entity.

Parameters
cacheMode:CacheMode

The CacheMode to use

Returns:IdentifierLoadAccess<T>

this, for method chaining

withback to summary
public default IdentifierLoadAccess<T> with(RootGraph<T> graph)

Deprecated

since 6.3.

use withLoadGraph

Annotations
@Deprecated
since:6.3
withback to summary
public IdentifierLoadAccess<T> with(RootGraph<T> graph, GraphSemantic semantic)

Customize the associations fetched by specifying an entity graph, and how it should be interpreted.

withFetchGraphback to summary
public 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.

withLoadGraphback to summary
public default IdentifierLoadAccess<T> withLoadGraph(RootGraph<T> graph)

Augment the associations fetched by default by specifying a list of additional associations to be fetched as an entity graph.

withReadOnlyback to summary
public IdentifierLoadAccess<T> withReadOnly(boolean readOnly)

Specify whether the entity should be loaded in read-only mode.

See Also
Session#setDefaultReadOnly(boolean)