ID
- is the type of the primary key
.public interface GenericEntity<ID> extends Serializable
GenericEntity
is identified by a primary key
.GenericEntity
has a modification counter
for optimistic locking (even
though not strictly required - you could statically return 0).javax.persistence.Entity
entity transfer-object
persistence entities
. On the other hand the higher layers always need to use
transfer-objects
. Our recommendation is to map between
these two in the logic-layer using the BeanMapper
component from the devon4j-beanmapping
module.javax.persistence.Entity
Modifier and Type | Method and Description |
---|---|
ID |
getId() |
int |
getModificationCounter()
This method gets the current modification-counter of this entity.
|
void |
setId(ID id) |
void |
setModificationCounter(int modificationCounter) |
ID getId()
null
if this entity is transient (not
yet saved
in the database). While this method is
initially defined in a generic way, it is strongly recommended to use 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
. Long
value you can still use Long
here and provide a transient getter method that returns the your custom datatype from the Long
.javax.persistence.Id
void setId(ID id)
id
- the new primary key
. This method shall typically only be used by technical frameworks
such as hibernate.int getModificationCounter()
persisted
, this counter will be increased (typically after
the transaction is closed). The initial value after construction is 0
. version
. However, as this sometimes causes
confusion or may conflict with a business property "version", we use the more technical and self-explanatory name
modificationCounter
.0
.javax.persistence.Version
,
javax.persistence.Version
void setModificationCounter(int modificationCounter)
modificationCounter
- the new modification counter
. This method shall
typically only be used by technical frameworks such as hibernate.Copyright © 2014–2019 devon4j-Team. All rights reserved.