public abstract class AbstractEto extends AbstractTo implements GenericEntity<Long>
transfer-object that contains all the data properties of
an entity without its relations. This is called ETO (entity transfer object).
Sometimes in other contexts people also call this DTO (data transfer object).String,
Number, Instant, custom-datatype, etc.). Relations of an @link GenericEntity entity} are
not contained except for IDs of javax.persistence.OneToOne relations. Instead of using
Long we recommend to use IdRef to be type-safe and more
expressive. For actual relations you will use CTOs to express what set of entities to transfer,
load, save, update, etc. without redundancies.Eto.| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractEto.PersistentEntityAccess
Inner class to grant access to internal persistent
entity reference of an
AbstractEto. |
| Modifier and Type | Field and Description |
|---|---|
private Long |
id |
private int |
modificationCounter |
private GenericEntity<Long> |
persistentEntity |
private static long |
serialVersionUID |
| Constructor and Description |
|---|
AbstractEto()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Long |
getId() |
int |
getModificationCounter()
This method gets the current modification-counter of this entity.
|
void |
setId(Long id) |
void |
setModificationCounter(int version) |
protected void |
toString(StringBuilder buffer)
Method to extend
AbstractTo.toString() logic. |
toStringprivate static final long serialVersionUID
private Long id
private int modificationCounter
private transient GenericEntity<Long> persistentEntity
public Long getId()
getId in interface GenericEntity<Long>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.Idpublic void setId(Long id)
setId in interface GenericEntity<Long>id - the new primary key. This method shall typically only be used by technical frameworks
such as hibernate.public int getModificationCounter()
GenericEntitypersisted, 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.getModificationCounter in interface GenericEntity<Long>javax.persistence.Version,
javax.persistence.Versionpublic void setModificationCounter(int version)
setModificationCounter in interface GenericEntity<Long>version - the new modification counter. This method shall
typically only be used by technical frameworks such as hibernate.protected void toString(StringBuilder buffer)
AbstractTo.toString() logic.toString in class AbstractTobuffer - is the StringBuilder where to append the string
representation.Copyright © 2014–2019 devon4j-Team. All rights reserved.