ID - is the type of the primary key.public abstract class AbstractGenericEntity<ID> extends Object implements MutableGenericEntity<ID>
MutableGenericEntity should inherit from
(if possible).| Modifier and Type | Field and Description |
|---|---|
private ID |
id |
private int |
modificationCounter |
private static long |
serialVersionUID
UID for serialization.
|
| Constructor and Description |
|---|
AbstractGenericEntity()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
ID |
getId()
This method gets the unique identifier (primary key) of this entity.
|
int |
getModificationCounter()
This method gets the current modification-counter of this entity.
|
int |
hashCode() |
void |
setId(ID id)
This method sets the
ID of this entity. |
void |
setModificationCounter(int version)
This method sets the
modification counter of this entity. |
protected void |
toString(StringBuilder buffer)
Method to extend
Object.toString() logic. |
private static final long serialVersionUID
private int modificationCounter
getModificationCounter()public ID getId()
Long as datatype for IDs. String-based business-oriented identifier it is best practice to use a
Long as 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 its string-representation. Datatype for it. If it can easily be mapped to a Long
value you can still use Long here and provide a transient getter method that returns the your
custom Datatype from the Long.getId in interface GenericEntity<ID>getId in interface AttributeReadId<ID>null if the object is
new and no ID has manually been assigned.public void setId(ID id)
ID of this entity. GeneratedValue and therefore managed by the persistence.
However, for final freedom we decided to add this method to the API (e.g. to copy from transfer-object to
persistent-entity and vice-versa).setId in interface MutableGenericEntity<ID>id - is the new value of GenericEntity.getId().public int getModificationCounter()
saved, this counter will be increased. The
initial value after construction is 0. 0.getModificationCounter in interface GenericEntity<ID>Versionpublic void setModificationCounter(int version)
modification counter of this entity. setModificationCounter in interface MutableGenericEntity<ID>version - is the new value of GenericEntity.getModificationCounter().protected void toString(StringBuilder buffer)
Object.toString() logic.buffer - is the StringBuilder where to append the
string representation.Copyright © 2001–2015 mmm-Team. All rights reserved.