Top Description Methods
org.hibernate

public Interface NaturalIdLoadAccess<T>

Known Direct Implementers
org.hibernate.internal.SessionImpl.NaturalIdLoadAccessImpl
Imports
java.io.Serializable, java.util.Optional

Loads an entity by its natural identifier.
Authors
Eric Dalquist, Steve Ebersole
See Also
org.hibernate.annotations.NaturalId

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the persistent instance or proxy
getReference
()

Return the persistent instance with the natural id value(s) defined by the call(s) to using.

public T

Returns:

The persistent instance or null
load
()

Return the persistent instance with the natural id value(s) defined by the call(s) to using, or null if there is no such persistent instance.

public Optional<T>

Returns:

The persistent instance, if one, wrapped in Optional
loadOptional
()

Same semantic as load except that here Optional is returned to handle nullability.

public NaturalIdLoadAccess<T>

Returns:

this, for method chaining
setSynchronizationEnabled
(boolean
Should synchronization be performed? true indicates synchronization will be performed; false indicates it will be circumvented.
enabled
)

For entities with mutable natural ids, should Hibernate perform "synchronization" prior to performing lookups?

public NaturalIdLoadAccess<T>

Returns:

this, for method chaining
using
(String
The entity attribute name that is marked as a NaturalId
attributeName
,
Object
The value of the attribute
value
)

Add a NaturalId attribute value.

public NaturalIdLoadAccess<T>

Returns:

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

Specify the LockOptions to use when retrieving the entity.

Method Detail

getReferenceback to summary
public T getReference()

Return the persistent instance with the natural id value(s) defined by the call(s) to using. 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:T

the persistent instance or proxy

loadback to summary
public T load()

Return the persistent instance with the natural id value(s) defined by the call(s) to using, 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.

Returns:T

The persistent instance or null

loadOptionalback to summary
public Optional<T> loadOptional()

Same semantic as load except that here Optional is returned to handle nullability.

Returns:Optional<T>

The persistent instance, if one, wrapped in Optional

setSynchronizationEnabledback to summary
public NaturalIdLoadAccess<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).

"synchronization" here indicates updating the natural-id -> pk cross reference maintained as part of 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 its natural-id values have changed and, if so, update the cross reference. There is a performance impact associated with this, so if application developers are certain the natural-ids in play have not changed, this setting can be disabled to circumvent that impact. However, disabling this setting when natural-ids values have changed can result in incorrect results!

Parameters
enabled:boolean

Should synchronization be performed? true indicates synchronization will be performed; false indicates it will be circumvented.

Returns:NaturalIdLoadAccess<T>

this, for method chaining

usingback to summary
public NaturalIdLoadAccess<T> using(String attributeName, Object value)

Add a NaturalId attribute value.

Parameters
attributeName:String

The entity attribute name that is marked as a NaturalId

value:Object

The value of the attribute

Returns:NaturalIdLoadAccess<T>

this, for method chaining

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

Specify the LockOptions to use when retrieving the entity.

Parameters
lockOptions:LockOptions

The lock options to use.

Returns:NaturalIdLoadAccess<T>

this, for method chaining