Interface GenericEntity<ID>
-
- Type Parameters:
ID- is the type of theprimary key.
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
PersistenceEntity<ID>,RevisionedEntity<ID>,RevisionedPersistenceEntity<ID>
- All Known Implementing Classes:
AbstractEto,RevisionedEto
public interface GenericEntity<ID> extends Serializable
This is the interface for an entity, which is an object that is potentially stored in a persistent store (typically a database via JPA). Every non-abstract implementation of this interface is simply called an entity. It is supposed to be a simple java bean.
This interface makes the following assumptions:- A
GenericEntityis identified by aprimary key. - A
GenericEntityhas amodification counterfor optimistic locking (even though not strictly required - you could statically return 0).
An instance of this interface is typically one of the following:- a JPA
Entity
- a
entity transfer-object
persistence entities. On the other hand the higher layers always need to usetransfer-objects. Our recommendation is to map between these two in the logic-layer using theBeanMappercomponent from thedevon4j-beanmappingmodule.- Since:
- 3.0.0
- See Also:
Entity
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description IDgetId()intgetModificationCounter()This method gets the current modification-counter of this entity.voidsetId(ID id)voidsetModificationCounter(int modificationCounter)
-
-
-
Method Detail
-
getId
ID getId()
- Returns:
- the primary key (unique identifier) of this entity. May be
nullif this entity is transient (not yetsavedin the database). While this method is initially defined in a generic way, it is strongly recommended to useLongas datatype for IDs.
Even if you want to have aString-based business-oriented identifier it is best practice to use aLongas primary key and add the business identifier as additional field (with a unique constraint). This way references to the entity will be a lot more compact and improve your performance in JOINs or the like. However, there may be reasons to use other datatypes for the ID. In any case the unique ID should be an immutable java-object that can be rebuild from itsstring-representation.
Please note that if your ID has a specific syntax, semantic, formatting rules, etc. you should create a custom datatype for it. If it can easily be mapped to aLongvalue you can still useLonghere and provide a transient getter method that returns the your custom datatype from theLong. - See Also:
Id
-
setId
void setId(ID id)
- Parameters:
id- the newprimary key. This method shall typically only be used by technical frameworks such as hibernate.
-
getModificationCounter
int getModificationCounter()
This method gets the current modification-counter of this entity. Whenever the object gets modified andpersisted, this counter will be increased (typically after the transaction is closed). The initial value after construction is0.
This property is often simply calledversion. However, as this sometimes causes confusion or may conflict with a business property "version", we use the more technical and self-explanatory namemodificationCounter.
If this feature is NOT supported for some reason, this method should always return0.- Returns:
- the current modification-counter.
- See Also:
Version,Version
-
setModificationCounter
void setModificationCounter(int modificationCounter)
- Parameters:
modificationCounter- the newmodification counter. This method shall typically only be used by technical frameworks such as hibernate.
-
-