Top Description Methods
org.hibernate

public Interface NaturalIdMultiLoadAccess<T>

Known Direct Implementers
org.hibernate.internal.NaturalIdMultiLoadAccessStandard
Imports
java.util.List, .Map, org.hibernate.graph.GraphSemantic, .RootGraph

Loads multiple instances of a given entity type at once, by specifying a list of natural id values. This allows the entities to be fetched from the database in batches.

List<Book> books =
        session.byMultipleNaturalId(Book.class)
            .withBatchSize(10)
            .multiLoad(isbnList);

Composite natural ids may be accommodated by passing a list of maps of type Map<String,Object> to multiLoad. Each map must contain the natural id attribute values keyed by @NaturalId attribute name.

var compositeNaturalId =
        Map.of(Book_.ISBN, isbn, Book_.PRINTING, printing);
See Also
Session#byMultipleNaturalId(Class), org.hibernate.annotations.NaturalId

Method Summary

Modifier and TypeMethod and Description
public static Map<String, ?>
compoundValue(Object... elements)

Deprecated since 6.3. use Map#of instead
Helper for creating a Map that represents the value of a composite natural id. An even number of arguments is expected, with each attribute name followed by its value.
public NaturalIdMultiLoadAccess<T>

Returns:

this, for method chaining
enableOrderedReturn
(boolean
true if entity instances should be ordered; false if they may be returned in any order.
enabled
)

Should the returned list of entity instances be ordered, with the position of an entity instance determined by the position of its identifier in the list if ids passed to multiLoad?

public NaturalIdMultiLoadAccess<T>

Returns:

this, for method chaining
enableReturnOfDeletedEntities
(boolean
true if removed entities should be returned; false if they should be replaced by null values.
enabled
)

Should multiLoad return entity instances that have been marked for removal in the current session, but not yet deleted in the database?

public List<T>

Returns:

The managed entities.
multiLoad
(Object...
The natural id values to load
ids
)

Retrieve the entities with the given natural id values.

public List<T>

Returns:

The managed entities.
multiLoad
(List<?>
The natural id values to load
ids
)

Retrieve the entities with the given natural id values.

public NaturalIdMultiLoadAccess<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 NaturalIdMultiLoadAccess<T>

Returns:

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

Specify the CacheMode to use when obtaining an entity.

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

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

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

public NaturalIdMultiLoadAccess<T>

Returns:

this, for method chaining
withBatchSize
(int
The batch size
batchSize
)

Specify a batch size, that is, how many entities should be fetched in each request to the database.

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

Method Detail

compoundValueback to summary
public static Map<String, ?> compoundValue(Object... elements)

Deprecated

since 6.3.

use Map#of instead

Helper for creating a Map that represents the value of a composite natural id. An even number of arguments is expected, with each attribute name followed by its value.

Annotations
@Deprecated
since:6.3
See Also
NaturalIdLoadAccess#using(Object...)
enableOrderedReturnback to summary
public NaturalIdMultiLoadAccess<T> enableOrderedReturn(boolean enabled)

Should the returned list of entity instances be ordered, with the position of an entity instance determined by the position of its identifier in the list if ids passed to multiLoad?

By default, the returned list is ordered and the positions of the entities correspond to the positions of their ids. In this case, the handling of entities marked for removal becomes important.

Parameters
enabled:boolean

true if entity instances should be ordered; false if they may be returned in any order.

Returns:NaturalIdMultiLoadAccess<T>

this, for method chaining

enableReturnOfDeletedEntitiesback to summary
public NaturalIdMultiLoadAccess<T> enableReturnOfDeletedEntities(boolean enabled)

Should multiLoad return entity instances that have been marked for removal in the current session, but not yet deleted in the database?

By default, instances marked for removal are replaced by null in the returned list of entities when enableOrderedReturn is used.

Parameters
enabled:boolean

true if removed entities should be returned; false if they should be replaced by null values.

Returns:NaturalIdMultiLoadAccess<T>

this, for method chaining

multiLoadback to summary
public List<T> multiLoad(Object... ids)

Retrieve the entities with the given natural id values.

Note that the options enableReturnOfDeletedEntities and enableOrderedReturn affect the size and shape of the returned list of entity instances.

Parameters
ids:Object[]

The natural id values to load

Returns:List<T>

The managed entities.

multiLoadback to summary
public List<T> multiLoad(List<?> ids)

Retrieve the entities with the given natural id values.

Note that the options enableReturnOfDeletedEntities and enableOrderedReturn affect the size and shape of the returned list of entity instances.

Parameters
ids:List<?>

The natural id values to load

Returns:List<T>

The managed entities.

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

Specify the lock options to use when querying the database.

Parameters
lockOptions:LockOptions

The lock options to use

Returns:NaturalIdMultiLoadAccess<T>

this, for method chaining

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

Specify the CacheMode to use when obtaining an entity.

Parameters
cacheMode:CacheMode

The CacheMode to use

Returns:NaturalIdMultiLoadAccess<T>

this, for method chaining

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

Deprecated

since 6.3.

use withLoadGraph

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

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

withBatchSizeback to summary
public NaturalIdMultiLoadAccess<T> withBatchSize(int batchSize)

Specify a batch size, that is, how many entities should be fetched in each request to the database.

  • By default, the batch sizing strategy is determined by the SQL dialect, but
  • if some batchSize>1 is specified as an argument to this method, then that batch size will be used.

If an explicit batch size is set manually, care should be taken to not exceed the capabilities of the underlying database.

A batch size is considered a hint.

Parameters
batchSize:int

The batch size

Returns:NaturalIdMultiLoadAccess<T>

this, for method chaining

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