Top Description Fields Methods
org.hibernate.metamodel.mapping

public Interface NaturalIdMapping

extends VirtualModelPart
Known Direct Implementers
org.hibernate.metamodel.mapping.internal.AbstractNaturalIdMapping
Annotations
@Incubating
Imports
java.util.List, org.hibernate.Incubating, org.hibernate.cache.spi.access.NaturalIdDataAccess, org.hibernate.engine.spi.SharedSessionContractImplementor, org.hibernate.loader.ast.spi.MultiNaturalIdLoader, .NaturalIdLoader

Mapping for an entity's natural-id, if one is defined.

Natural identifiers are an alternative form of uniquely identifying a specific row. In this sense, they are similar to a primary key. In fact most natural identifiers will also be classified as "candidate keys" (as in a column or group of columns that are considered candidates for primary-key).

However, a natural id has fewer restrictions than a primary key. While these lessened restrictions make them inappropriate for use as a primary key, they are still generally usable as unique locators with caveats. General reasons a natural id might be inappropriate for use as a primary key are

See other sources for a more complete discussion of data modeling.

Author
Steve Ebersole
See Also
org.hibernate.Session#byNaturalId, org.hibernate.Session#bySimpleNaturalId, org.hibernate.Session#byMultipleNaturalId

Field Summary

Modifier and TypeField and Description
public static final String

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

The hash-code
calculateHashCode
(Object
The natural-id value
value
)

Calculate the hash-code of a natural-id value

public Object

Returns:

The extracted natural id values
extractNaturalIdFromEntity
(Object
The entity instance
entity
)

Given an entity instance, extract the normalized natural id representation

public Object

Returns:

The extracted natural id values. This is a normalized
extractNaturalIdFromEntityState
(Object[]
The attribute state array
state
)

Given an array of "full entity state", extract the normalized natural id representation

public NaturalIdDataAccess
getCacheAccess()

Access to the natural-id's L2 cache access.

public List<SingularAttributeMapping>
getNaturalIdAttributes()

The attribute(s) making up the natural-id.

public default String
getPartName()

Implements org.hibernate.metamodel.mapping.ModelPart.getPartName.

The local part name, which is generally the unqualified role name
public boolean
isMutable()

Whether the natural-id is immutable.

public NaturalIdLoader<?>
makeLoader(EntityMappingType entityDescriptor)

Make a loader capable of loading a single entity by natural-id

public MultiNaturalIdLoader<?>
makeMultiLoader(EntityMappingType entityDescriptor)

Make a loader capable of loading multiple entities by natural-id

public Object

Returns:

The normalized, internal representation
normalizeInput
(Object
The user-supplied value
incoming
)

Normalize a user-provided natural-id value into the representation Hibernate uses internally

public void
validateInternalForm(Object naturalIdValue)

Validates a natural id value(s) for the described natural-id based on the expected internal representation

public void
verifyFlushState(Object id, Object[] currentState, Object[] loadedState, SharedSessionContractImplementor session)

Verify the natural-id value(s) we are about to flush to the database

Inherited from org.hibernate.metamodel.mapping.VirtualModelPart:
isVirtual

Field Detail

PART_NAMEback to summary
public static final String PART_NAME

Method Detail

calculateHashCodeback to summary
public int calculateHashCode(Object value)

Calculate the hash-code of a natural-id value

Parameters
value:Object

The natural-id value

Returns:int

The hash-code

extractNaturalIdFromEntityback to summary
public Object extractNaturalIdFromEntity(Object entity)

Given an entity instance, extract the normalized natural id representation

Parameters
entity:Object

The entity instance

Returns:Object

The extracted natural id values

extractNaturalIdFromEntityStateback to summary
public Object extractNaturalIdFromEntityState(Object[] state)

Given an array of "full entity state", extract the normalized natural id representation

Parameters
state:Object[]

The attribute state array

Returns:Object

The extracted natural id values. This is a normalized

getCacheAccessback to summary
public NaturalIdDataAccess getCacheAccess()

Access to the natural-id's L2 cache access. Returns null if the natural-id is not configured for caching

getNaturalIdAttributesback to summary
public List<SingularAttributeMapping> getNaturalIdAttributes()

The attribute(s) making up the natural-id.

getPartNameback to summary
public default String getPartName()

Implements org.hibernate.metamodel.mapping.ModelPart.getPartName.

Doc from org.hibernate.metamodel.mapping.ModelPart.getPartName.

The local part name, which is generally the unqualified role name

Annotations
@Override
isMutableback to summary
public boolean isMutable()

Whether the natural-id is immutable. This is the same as saying that none of the attributes are mutable

makeLoaderback to summary
public NaturalIdLoader<?> makeLoader(EntityMappingType entityDescriptor)

Make a loader capable of loading a single entity by natural-id

makeMultiLoaderback to summary
public MultiNaturalIdLoader<?> makeMultiLoader(EntityMappingType entityDescriptor)

Make a loader capable of loading multiple entities by natural-id

normalizeInputback to summary
public Object normalizeInput(Object incoming)

Normalize a user-provided natural-id value into the representation Hibernate uses internally

Parameters
incoming:Object

The user-supplied value

Returns:Object

The normalized, internal representation

validateInternalFormback to summary
public void validateInternalForm(Object naturalIdValue)

Validates a natural id value(s) for the described natural-id based on the expected internal representation

verifyFlushStateback to summary
public void verifyFlushState(Object id, Object[] currentState, Object[] loadedState, SharedSessionContractImplementor session)

Verify the natural-id value(s) we are about to flush to the database