org.springframework.data.mapping

## Interface PersistentEntity<T,P extends PersistentProperty<P>>

All Superinterfaces:
  Iterable<P>

All Known Subinterfaces:
  MutablePersistentEntity<T,P>

All Known Implementing Classes:
  BasicPersistentEntity

    public interface PersistentEntity<T,P extends PersistentProperty<P>>
    extends Iterable<P>

Represents a persistent entity.

Author:
  Oliver Gierke, Graeme Rocher, Jon Brisbin, Patryk Wasik, Mark Paluch, Christoph Strobl

### Method Summary

All Methods Instance Methods Abstract Methods Default Methods
`void` `doWithAssociations(AssociationHandler<P> handler)` Applies the given `AssociationHandler` to all `Association` contained in this `PersistentEntity`.
`void` `doWithAssociations(SimpleAssociationHandler handler)`
`void` `doWithProperties(PropertyHandler<P> handler)` Applies the given `PropertyHandler` to all `PersistentProperty`s contained in this `PersistentEntity`.
`void` `doWithProperties(SimplePropertyHandler handler)`
`<A extends Annotation> A` `findAnnotation(Class<A> annotationType)` Looks up the annotation of the given type on the `PersistentEntity`.
`IdentifierAccessor` `getIdentifierAccessor(Object bean)` Returns the `IdentifierAccessor` for the given bean.
`P` `getIdProperty()` Returns the id property of the `PersistentEntity`.
`String` `getName()` The entity name including any package prefix.
`PreferredConstructor<T,P>` `getPersistenceConstructor()` Returns the `PreferredConstructor` to be used to instantiate objects of this `PersistentEntity`.
`Iterable<P>` `getPersistentProperties(Class<? extends Annotation> annotationType)` Returns all properties equipped with an `Annotation` of the given type.
`default P` `getPersistentProperty(Class<? extends Annotation> annotationType)` Returns the first property equipped with an `Annotation` of the given type.
`P` `getPersistentProperty(String name)` Obtains a `PersistentProperty` instance by name.
`<B> PersistentPropertyAccessor<B>` `getPropertyAccessor(B bean)` Returns a `PersistentPropertyAccessor` to access property values of the given bean.
`<B> PersistentPropertyPathAccessor<B>` `getPropertyPathAccessor(B bean)` Returns a `PersistentPropertyPathAccessor` to access property values of the given bean.
`default <A extends Annotation> A` `getRequiredAnnotation(Class<A> annotationType)` Returns the required annotation of the given type on the `PersistentEntity`.
`default P` `getRequiredIdProperty()` Returns the id property of the `PersistentEntity`.
`default P` `getRequiredPersistentProperty(String name)` Returns the `PersistentProperty` with the given name.
`default P` `getRequiredVersionProperty()` Returns the version property of the `PersistentEntity`.
`Class<T>` `getType()` Returns the resolved Java type of this entity.
`Alias` `getTypeAlias()` Returns the alias to be used when storing type information.
`TypeInformation<T>` `getTypeInformation()` Returns the `TypeInformation` backing this `PersistentEntity`.
`P` `getVersionProperty()` Returns the version property of the `PersistentEntity`.
`boolean` `hasIdProperty()` Returns whether the `PersistentEntity` has an id property.
`boolean` `hasVersionProperty()` Returns whether the `PersistentEntity` has a version property.
`<A extends Annotation> boolean` `isAnnotationPresent(Class<A> annotationType)` Checks whether the annotation of the given type is present on the `PersistentEntity`.
`boolean` `isConstructorArgument(PersistentProperty<?> property)` Returns whether the given `PersistentProperty` is referred to by a constructor argument of the `PersistentEntity`.
`boolean` `isIdProperty(PersistentProperty<?> property)` Returns whether the given `PersistentProperty` is the id property of the entity.
`boolean` `isImmutable()` Returns whether the entity is considered immutable, i.e. clients shouldn't attempt to change instances via the `PersistentPropertyAccessor` obtained via `getPropertyAccessor(Object)`.
`boolean` `isNew(Object bean)` Returns whether the given bean is considered new according to the static metadata.
`boolean` `isVersionProperty(PersistentProperty<?> property)` Returns whether the given `PersistentProperty` is the version property of the entity.
`boolean` `requiresPropertyPopulation()` Returns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.

### Methods inherited from interface java.lang.Iterable

`forEach, iterator, spliterator`

### Method Detail

#### getName

    String getName()

The entity name including any package prefix.

Returns:
  must never return null.

#### getPersistenceConstructor

    @Nullable
    PreferredConstructor<T,P> getPersistenceConstructor()

Returns the `PreferredConstructor` to be used to instantiate objects of this `PersistentEntity`.

Returns:
  null in case no suitable constructor for automatic construction can be found. This usually indicates that the instantiation of the object of that persistent entity is done through either a customer `EntityInstantiator` or handled by custom conversion mechanisms entirely.

#### isConstructorArgument

    boolean isConstructorArgument(PersistentProperty<?> property)

Returns whether the given `PersistentProperty` is referred to by a constructor argument of the `PersistentEntity`.

Parameters:
  `property` - can be null.
Returns:
  true if the given `PersistentProperty` is referred to by a constructor argument or false if not or null.

#### isIdProperty

    boolean isIdProperty(PersistentProperty<?> property)

Returns whether the given `PersistentProperty` is the id property of the entity.

Parameters:
  `property` - can be null.
Returns:
  true given property is the entities id.

#### isVersionProperty

    boolean isVersionProperty(PersistentProperty<?> property)

Returns whether the given `PersistentProperty` is the version property of the entity.

Parameters:
  `property` - can be null.
Returns:
  true given property is used as version.

#### getIdProperty

    @Nullable
    P getIdProperty()

Returns the id property of the `PersistentEntity`. Can be null in case this is an entity completely handled by a custom conversion.

Returns:
  the id property of the `PersistentEntity`.

#### getRequiredIdProperty

    default P getRequiredIdProperty()

Returns the id property of the `PersistentEntity`.

Returns:
  the id property of the `PersistentEntity`.
Throws:
  `IllegalStateException` - if `PersistentEntity` does not define an id property.
Since:
  2.0

#### getVersionProperty

    @Nullable
    P getVersionProperty()

Returns the version property of the `PersistentEntity`. Can be null in case no version property is available on the entity.

Returns:
  the version property of the `PersistentEntity`.

#### getRequiredVersionProperty

    default P getRequiredVersionProperty()

Returns the version property of the `PersistentEntity`. Can be null in case no version property is available on the entity.

Returns:
  the version property of the `PersistentEntity`.
Throws:
  `IllegalStateException` - if `PersistentEntity` does not define a version property.
Since:
  2.0

#### getPersistentProperty

    @Nullable
    P getPersistentProperty(String name)

Obtains a `PersistentProperty` instance by name.

Parameters:
  `name` - The name of the property. Can be null.
Returns:
  the `PersistentProperty` or null if it doesn't exist.

#### getRequiredPersistentProperty

    default P getRequiredPersistentProperty(String name)

Returns the `PersistentProperty` with the given name.

Parameters:
  `name` - the name of the property. Can be null or empty.
Returns:
  the `PersistentProperty` with the given name.
Throws:
  `IllegalStateException` - in case no property with the given name exists.

#### getPersistentProperty

    @Nullable
    default P getPersistentProperty(Class<? extends Annotation> annotationType)

Returns the first property equipped with an `Annotation` of the given type.

Parameters:
  `annotationType` - must not be null.
Returns:
  null if no property found with given annotation type.
Since:
  1.8

#### getPersistentProperties

    Iterable<P> getPersistentProperties(Class<? extends Annotation> annotationType)

Returns all properties equipped with an `Annotation` of the given type.

Parameters:
  `annotationType` - must not be null.
Returns:
  empty `Iterator` if no match found. Never null.
Since:
  2.0

#### hasIdProperty

    boolean hasIdProperty()

Returns whether the `PersistentEntity` has an id property. If this call returns true, `getIdProperty()` will return a non-null value.

Returns:
  true if entity has an id property.

#### hasVersionProperty

    boolean hasVersionProperty()

Returns whether the `PersistentEntity` has a version property. If this call returns true, `getVersionProperty()` will return a non-null value.

Returns:
  true if entity has a version property.

#### getType

    Class<T> getType()

Returns the resolved Java type of this entity.

Returns:
  The underlying Java class for this entity. Never null.

#### getTypeAlias

    Alias getTypeAlias()

Returns the alias to be used when storing type information. Might be null to indicate that there was no alias defined through the mapping metadata.

Returns:

#### getTypeInformation

    TypeInformation<T> getTypeInformation()

Returns the `TypeInformation` backing this `PersistentEntity`.

Returns:

#### doWithProperties

    void doWithProperties(PropertyHandler<P> handler)

Applies the given `PropertyHandler` to all `PersistentProperty`s contained in this `PersistentEntity`.

Parameters:
  `handler` - must not be null.

#### doWithProperties

    void doWithProperties(SimplePropertyHandler handler)

#### doWithAssociations

    void doWithAssociations(AssociationHandler<P> handler)

Applies the given `AssociationHandler` to all `Association` contained in this `PersistentEntity`.

Parameters:
  `handler` - must not be null.

#### doWithAssociations

    void doWithAssociations(SimpleAssociationHandler handler)

#### findAnnotation

    @Nullable
    <A extends Annotation> A findAnnotation(Class<A> annotationType)

Looks up the annotation of the given type on the `PersistentEntity`.

Parameters:
  `annotationType` - must not be null.
Returns:
  null if not found.
Since:
  1.8

#### getRequiredAnnotation

    default <A extends Annotation> A getRequiredAnnotation(Class<A> annotationType)
                                                    throws IllegalStateException

Returns the required annotation of the given type on the `PersistentEntity`.

Parameters:
  `annotationType` - must not be null.
Returns:
  the annotation.
Throws:
  `IllegalStateException` - if the required `annotationType` is not found.
Since:
  2.0

#### isAnnotationPresent

    <A extends Annotation> boolean isAnnotationPresent(Class<A> annotationType)

Checks whether the annotation of the given type is present on the `PersistentEntity`.

Parameters:
  `annotationType` - must not be null.
Returns:
  true if `Annotation` of given type is present.
Since:
  2.0

#### getPropertyAccessor

    <B> PersistentPropertyAccessor<B> getPropertyAccessor(B bean)

Returns a `PersistentPropertyAccessor` to access property values of the given bean.

Parameters:
  `bean` - must not be null.
Returns:
  new `PersistentPropertyAccessor`.
Since:
  1.10

#### getPropertyPathAccessor

    <B> PersistentPropertyPathAccessor<B> getPropertyPathAccessor(B bean)

Returns a `PersistentPropertyPathAccessor` to access property values of the given bean.

Parameters:
  `bean` - must not be null.
Returns:
  a new `PersistentPropertyPathAccessor`
Since:
  2.3

#### getIdentifierAccessor

    IdentifierAccessor getIdentifierAccessor(Object bean)

Returns the `IdentifierAccessor` for the given bean.

Parameters:
  `bean` - must not be null.
Returns:
  new `IdentifierAccessor`.
Since:
  1.10

#### isNew

    boolean isNew(Object bean)

Returns whether the given bean is considered new according to the static metadata.

Parameters:
  `bean` - must not be null.
Returns:
  whether the given bean is considered a new instance.
Throws:
  `IllegalArgumentException` - in case the given bean is not an instance of the typ represented by the `PersistentEntity`.

#### isImmutable

    boolean isImmutable()

Returns whether the entity is considered immutable, i.e. clients shouldn't attempt to change instances via the `PersistentPropertyAccessor` obtained via `getPropertyAccessor(Object)`.

Returns:
Since:
  2.1
See Also:
  `Immutable`

#### requiresPropertyPopulation

    boolean requiresPropertyPopulation()

Returns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.

Returns:
Since:
  2.1