Class BaseEntity

java.lang.Object
com.app.persistence.entity.BaseEntity
Direct Known Subclasses:
HolidayEntity, UserEntity, VerificationTokenEntity

@MappedSuperclass public class BaseEntity extends Object
Base entity class to be extended by all JPA entities. Provides a common identifier property `id` with auto-generated value, and overrides equals(Object) and hashCode() methods to ensure correct entity equality semantics, including support for Hibernate proxies.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Long
    The unique identifier of the entity.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Determines equality of entities based on their identifier.
    final int
    Returns a hash code consistent with the equals method.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • id

      protected Long id
      The unique identifier of the entity.
  • Constructor Details

    • BaseEntity

      public BaseEntity()
  • Method Details

    • equals

      public final boolean equals(Object o)
      Determines equality of entities based on their identifier. Takes into account Hibernate proxies to avoid issues with lazy loading.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare to
      Returns:
      true if entities are the same or have the same non-null id; false otherwise
    • hashCode

      public final int hashCode()
      Returns a hash code consistent with the equals method. Uses the class hash code, accounting for Hibernate proxy classes.
      Overrides:
      hashCode in class Object
      Returns:
      hash code of the entity