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.
org.hibernate.Session#byNaturalId , org.hibernate.Session#bySimpleNaturalId , org.hibernate.Session#byMultipleNaturalId
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: The hash-codeThe natural-id value value)Calculate the hash-code of a natural-id value |
| public Object | Returns: The extracted natural id valuesThe entity instance entity)Given an entity instance, extract the normalized natural id representation |
| public Object | Returns: The extracted natural id values. This is a normalizedThe attribute state array state)Given an array of "full entity state", extract the normalized natural id representation |
| public NaturalIdDataAccess | |
| public List | |
| public default String | getPartName()
Implements org. |
| public boolean | |
| 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 representationThe 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 |
| PART_NAME | back to summary |
|---|---|
| public static final String PART_NAME | |
| calculateHashCode | back to summary |
|---|---|
| public int calculateHashCode(Object value) Calculate the hash-code of a natural-id value
| |
| extractNaturalIdFromEntity | back to summary |
|---|---|
| public Object extractNaturalIdFromEntity(Object entity) Given an entity instance, extract the normalized natural id representation | |
| extractNaturalIdFromEntityState | back to summary |
|---|---|
| public Object extractNaturalIdFromEntityState(Object[] state) Given an array of "full entity state", extract the normalized natural id representation | |
| getCacheAccess | back 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 | |
| getNaturalIdAttributes | back to summary |
|---|---|
| public List The attribute(s) making up the natural-id. | |
| getPartName | back to summary |
|---|---|
| public default String getPartName() Implements org. Doc from org. The local part name, which is generally the unqualified role name
| |
| isMutable | back to summary |
|---|---|
| public boolean isMutable() Whether the natural-id is immutable. This is the same as saying that none of the attributes are mutable | |
| makeLoader | back to summary |
|---|---|
| public NaturalIdLoader Make a loader capable of loading a single entity by natural-id | |
| makeMultiLoader | back to summary |
|---|---|
| public MultiNaturalIdLoader Make a loader capable of loading multiple entities by natural-id | |
| normalizeInput | back to summary |
|---|---|
| public Object normalizeInput(Object incoming) Normalize a user-provided natural-id value into the representation Hibernate uses internally | |
| validateInternalForm | back to summary |
|---|---|
| public void validateInternalForm(Object naturalIdValue) Validates a natural id value(s) for the described natural-id based on the expected internal representation | |
| verifyFlushState | back 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 | |