Class BaseDataEntity<ID extends Serializable>
java.lang.Object
com.ultikits.ultitools.abstracts.data.BaseDataEntity<ID>
- Type Parameters:
ID- the type of the entity identifier
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AuditableDataEntity
public abstract class BaseDataEntity<ID extends Serializable>
extends Object
implements Serializable
Enhanced abstract data entity with generic ID type and lifecycle hooks.
Provides a type-safe foundation for persistent data entities.
This class declares its own id field, typed ID rather than Object.
Before 6.3.0 this class extended the now-removed AbstractDataEntity and reused its
Object-typed id field instead of declaring one directly, specifically to avoid
Gson's "declares multiple JSON fields named 'id'" error, which fires when two classes in the
same hierarchy both declare a field mapped to the same JSON key. With
AbstractDataEntity deleted this class is now the only declarer of id in its own
hierarchy, so that collision cannot occur and the extra indirection is no longer needed.
- Since:
- 6.2.0
- Version:
- 2.0.0
- Author:
- wisdomme
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate IDThe entity's identifier, owned directly by this class (see the class javadoc for why this moved here from the now-removedAbstractDataEntity).private static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Objectclone()<T extends BaseDataEntity<ID>>
TCreates a copy of this entity without the ID.getId()Gets the entity ID.Gets validation error messages if validation fails.booleanisNew()Checks if this entity is new (not yet persisted).voidonCreate()Called before the entity is persisted for the first time.voidonDelete()Called before the entity is deleted.voidonLoad()Called after the entity is loaded from the data store.voidonUpdate()Called before the entity is updated.voidSets the entity ID.booleanvalidate()Validates the entity before persistence operations.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
id
The entity's identifier, owned directly by this class (see the class javadoc for why this moved here from the now-removedAbstractDataEntity).
-
-
Constructor Details
-
BaseDataEntity
public BaseDataEntity()
-
-
Method Details
-
getId
Gets the entity ID.- Returns:
- the typed entity ID
-
setId
Sets the entity ID.- Parameters:
id- the entity ID to set
-
onCreate
public void onCreate()Called before the entity is persisted for the first time. Override to add custom pre-insert logic. -
onUpdate
public void onUpdate()Called before the entity is updated. Override to add custom pre-update logic. -
onDelete
public void onDelete()Called before the entity is deleted. Override to add custom pre-delete logic. -
onLoad
public void onLoad()Called after the entity is loaded from the data store. Override to add custom post-load logic. -
validate
public boolean validate()Validates the entity before persistence operations. Override to add custom validation logic.- Returns:
- true if the entity is valid, false otherwise
-
getValidationErrors
Gets validation error messages if validation fails. Override along withvalidate()to provide error messages.- Returns:
- list of validation error messages, empty if valid
-
isNew
public boolean isNew()Checks if this entity is new (not yet persisted).- Returns:
- true if the entity has no ID, false otherwise
-
copyWithoutId
Creates a copy of this entity without the ID. Useful for creating new entities based on existing ones.- Returns:
- a new entity with the same data but no ID
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-