Class BaseDataEntity<ID extends Serializable>

java.lang.Object
com.ultikits.ultitools.abstracts.AbstractDataEntity
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 AbstractDataEntity implements Serializable
Enhanced abstract data entity with generic ID type and lifecycle hooks. Provides a type-safe foundation for persistent data entities. Extends AbstractDataEntity to maintain compatibility with existing data operators.

Note: This class does NOT declare its own id field. It reuses the parent AbstractDataEntity id field (type Object) and provides typed accessors via getId() and setId(Serializable). This avoids Gson's "declares multiple JSON fields named 'id'" error.

带有泛型 ID 类型和生命周期钩子的增强型抽象数据实体。 为持久化数据实体提供类型安全的基础。 继承 AbstractDataEntity 以保持与现有数据操作器的兼容性。

Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
See Also:
  • Field Details

  • Constructor Details

    • BaseDataEntity

      public BaseDataEntity()
  • Method Details

    • getId

      public ID getId()
      Gets the entity ID with proper type casting. Delegates to parent's Object-typed id field.
      Returns:
      the typed entity ID
    • setId

      public void setId(ID id)
      Sets the entity ID. Delegates to parent's Object-typed id field.
      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.

      如果验证失败,获取验证错误消息。 与 validate() 一起重写以提供错误消息。

      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.

      创建此实体的副本(不含 ID)。 对于基于现有实体创建新实体很有用。

      Returns:
      a new entity with the same data but no ID
    • clone

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