I
- The type of the entity identifier.public abstract class BaseEntity<I> extends Object implements Entity<I>
Entity
,DomainEntity
(but this limits the ability to
use framework features). This base class provides equals(Object)
and hashCode()
methods based on the
entity identity. It also provides auto-detection of the identity field by reflection (see getId()
).
Constructor and Description |
---|
BaseEntity() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other)
As per Domain-Driven Design semantics, entity equality must be computed on its identity only,
as returned by the
Entity.getId() method. |
I |
getId()
Returns the identifier of the entity if present.
|
int |
hashCode()
As per Domain-Driven Design semantics, the hash code of an entity must be computed on its
identity only, as return by as returned by the
Entity.getId() method. |
String |
toString() |
public I getId()
Identity
,If the entity the identity field does not satisfy any of the conditions above, this method must be overridden to return the entity identity value.
public int hashCode()
Entity
Entity.getId()
method.public boolean equals(Object other)
Entity
Entity.getId()
method. Two entities from the same class hierarchy (with an
inheritance relationship between them) can be checked for equality as they have a comparable
identity.
When implementing this method for entities, the semantics above must be respected in
addition to the semantics of Object.equals(Object)
.
Copyright © 2013-2018–2019 SeedStack. All rights reserved.