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

    Fields
    Modifier and Type
    Field
    Description
    private ID
    The entity's identifier, owned directly by this class (see the class javadoc for why this moved here from the now-removed AbstractDataEntity).
    private static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Object
     
    <T extends BaseDataEntity<ID>>
    T
    Creates a copy of this entity without the ID.
    Gets the entity ID.
    Gets validation error messages if validation fails.
    boolean
    Checks if this entity is new (not yet persisted).
    void
    Called before the entity is persisted for the first time.
    void
    Called before the entity is deleted.
    void
    Called after the entity is loaded from the data store.
    void
    Called before the entity is updated.
    void
    setId(ID id)
    Sets the entity ID.
    boolean
    Validates the entity before persistence operations.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • id

      private ID extends Serializable id
      The entity's identifier, owned directly by this class (see the class javadoc for why this moved here from the now-removed AbstractDataEntity).
  • Constructor Details

    • BaseDataEntity

      public BaseDataEntity()
  • Method Details

    • getId

      public ID getId()
      Gets the entity ID.
      Returns:
      the typed entity ID
    • setId

      public void setId(ID id)
      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

      public List<String> getValidationErrors()
      Gets validation error messages if validation fails. Override along with validate() 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

      public <T extends BaseDataEntity<ID>> T 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

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException