Interface NaturalIdLoadAccess<T>
-
- All Known Implementing Classes:
NaturalIdLoadAccessImpl
public interface NaturalIdLoadAccess<T>
Loads an entity by its natural identifier.This is a generic form of load-by-natural-id covering both a single attribute and multiple attributes as the natural-id. For natural-ids defined by a single attribute,
SimpleNaturalIdLoadAccess
offers simplified access.- See Also:
NaturalId
,Session.byNaturalId(java.lang.String)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
getReference()
Return the persistent instance with the natural id value(s) defined by the call(s) tousing(java.lang.String, java.lang.Object)
.T
load()
Return the persistent instance with the natural id value(s) defined by the call(s) tousing(java.lang.String, java.lang.Object)
, ornull
if there is no such persistent instance.Optional<T>
loadOptional()
NaturalIdLoadAccess<T>
setSynchronizationEnabled(boolean enabled)
For entities with mutable natural ids, should natural ids be synchronized prior to performing a lookup? The default, for correctness, is to synchronize.NaturalIdLoadAccess<T>
using(Object... mappings)
Set multiple natural-id attribute values at once.NaturalIdLoadAccess<T>
using(String attributeName, Object value)
Add a NaturalId attribute value.NaturalIdLoadAccess<T>
with(LockOptions lockOptions)
Specify theLockOptions
to use when retrieving the entity.
-
-
-
Method Detail
-
with
NaturalIdLoadAccess<T> with(LockOptions lockOptions)
Specify theLockOptions
to use when retrieving the entity.- Parameters:
lockOptions
- The lock options to use.- Returns:
this
, for method chaining
-
using
NaturalIdLoadAccess<T> using(String attributeName, Object value)
Add a NaturalId attribute value.- Parameters:
attributeName
- The entity attribute name that is marked as a NaturalIdvalue
- The value of the attribute- Returns:
this
, for method chaining
-
using
NaturalIdLoadAccess<T> using(Object... mappings)
Set multiple natural-id attribute values at once. The passed array is expected to have an even number of elements, with the attribute name followed by its value, for example,using( "system", "matrix", "username", "neo" )
.- Returns:
this
, for method chaining
-
setSynchronizationEnabled
NaturalIdLoadAccess<T> setSynchronizationEnabled(boolean enabled)
For entities with mutable natural ids, should natural ids be synchronized prior to performing a lookup? The default, for correctness, is to synchronize.Here "synchronization" means updating the natural id to primary key cross-reference maintained by the session. When enabled, prior to performing the lookup, Hibernate will check all entities of the given type associated with the session to see if any natural id values have changed and, if so, update the cross-reference. There is a performance penalty associated with this, so if it is completely certain the no natural id in play has changed, this setting can be disabled to circumvent that impact. Disabling this setting when natural id values have changed can result in incorrect results!
- 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()
Return the persistent instance with the natural id value(s) defined by the call(s) tousing(java.lang.String, java.lang.Object)
. 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.- Returns:
- the persistent instance or proxy
-
load
T load()
Return the persistent instance with the natural id value(s) defined by the call(s) tousing(java.lang.String, java.lang.Object)
, 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.- Returns:
- The persistent instance or
null
-
-