Package org.hibernate
Interface SimpleNaturalIdLoadAccess<T>
-
- All Known Implementing Classes:
SimpleNaturalIdLoadAccessImpl
public interface SimpleNaturalIdLoadAccess<T>
Loads an entity by its natural identifier. This simplified API is used when the entity has exactly one field or property annotated@NaturalId
. If an entity has multiple attributes annotated@NaturalId
, thenNaturalIdLoadAccess
should be used instead.Book book = session.bySimpleNaturalId(Book.class).load(isbn);
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description SimpleNaturalIdLoadAccess<T>
disableFetchProfile(String profileName)
Customize the associations fetched by specifying a fetch profile that should be disabled during this operation.SimpleNaturalIdLoadAccess<T>
enableFetchProfile(String profileName)
Customize the associations fetched by specifying a fetch profile that should be enabled during this operation.T
getReference(Object naturalIdValue)
Return the persistent instance with the given natural id value, assuming that the instance exists.T
load(Object naturalIdValue)
Return the persistent instance with the given natural id value, ornull
if there is no such persistent instance.Optional<T>
loadOptional(Object naturalIdValue)
Just likeload(java.lang.Object)
, except that here anOptional
is returned.SimpleNaturalIdLoadAccess<T>
setSynchronizationEnabled(boolean enabled)
For entities with mutable natural ids, should Hibernate perform "synchronization" prior to performing lookups? The default is to perform "synchronization" (for correctness).SimpleNaturalIdLoadAccess<T>
with(RootGraph<T> graph, GraphSemantic semantic)
Customize the associations fetched by specifying an entity graph, and how it should be interpreted.SimpleNaturalIdLoadAccess<T>
with(LockOptions lockOptions)
Specify the lock options to use when querying the database.default SimpleNaturalIdLoadAccess<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.default SimpleNaturalIdLoadAccess<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
-
with
SimpleNaturalIdLoadAccess<T> with(LockOptions lockOptions)
Specify the lock options to use when querying the database.- Parameters:
lockOptions
- The lock options to use- Returns:
this
, for method chaining
-
withFetchGraph
default SimpleNaturalIdLoadAccess<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.
-
withLoadGraph
default SimpleNaturalIdLoadAccess<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.
-
with
SimpleNaturalIdLoadAccess<T> with(RootGraph<T> graph, GraphSemantic semantic)
Customize the associations fetched by specifying an entity graph, and how it should be interpreted.
-
enableFetchProfile
SimpleNaturalIdLoadAccess<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
-
disableFetchProfile
SimpleNaturalIdLoadAccess<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
-
setSynchronizationEnabled
SimpleNaturalIdLoadAccess<T> setSynchronizationEnabled(boolean enabled)
For entities with mutable natural ids, should Hibernate perform "synchronization" prior to performing lookups? The default is to perform "synchronization" (for correctness).See
NaturalIdLoadAccess.setSynchronizationEnabled(boolean)
for detailed discussion.- Parameters:
enabled
- Should synchronization be performed?true
indicates synchronization will be performed;false
indicates it will be circumvented.- Returns:
this
, for method chaining
-
getReference
T getReference(Object naturalIdValue)
Return the persistent instance with the given natural id value, 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.- Parameters:
naturalIdValue
- The value of the natural id- Returns:
- The persistent instance or proxy, if an instance exists.
Otherwise,
null
.
-
load
T load(Object naturalIdValue)
Return the persistent instance with the given natural id value, ornull
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:
naturalIdValue
- The value of the natural-id- Returns:
- The persistent instance or
null
-
-