Class DefaultBaseEntity

java.lang.Object
org.minijax.dao.DefaultBaseEntity
All Implemented Interfaces:
java.io.Serializable, BaseEntity
Direct Known Subclasses:
DefaultNamedEntity

@MappedSuperclass
public abstract class DefaultBaseEntity
extends java.lang.Object
implements BaseEntity
The BaseEntity class is the abstract base class for all web primitives. ID's are set by the class. ID's are *not* populated by JPA. For background:
  • https://stackoverflow.com/questions/5031614/the-jpa-hashcode-equals-dilemma
  • http://www.onjava.com/pub/a/onjava/2006/09/13/dont-let-hibernate-steal-your-identity.html
See Also:
Serialized Form
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected DefaultBaseEntity()  
  • Method Summary

    Modifier and Type Method Description
    <T extends DefaultBaseEntity>
    void
    copyNonNullProperties​(T other)
    Copies all non-null properties from the other object to this object.
    boolean equals​(java.lang.Object obj)
    Determines if this object equals another.
    static <T extends DefaultBaseEntity>
    T
    fromJson​(java.lang.Class<T> c, java.lang.String str)  
    java.time.Instant getCreatedDateTime()
    Returns the date/time when the object was created in the database.
    java.time.Instant getDeletedDateTime()
    Returns the date/time when the object was last deleted in the database.
    java.util.UUID getId()
    Returns the ID of the object.
    java.time.Instant getUpdatedDateTime()
    Returns the date/time when the object was last updated in the database.
    int hashCode()
    Returns a hash code for this details object.
    boolean isDeleted()
    Returns whether the object is deleted.
    void onPrePersist()  
    void onPreUpdate()  
    void setCreatedDateTime​(java.time.Instant createdDateTime)
    Sets the date/time when the object was created in the database.
    void setDeleted​(boolean deleted)
    Marks the entity as deleted.
    void setId​(java.util.UUID id)
    Sets the ID of the object.
    void setUpdatedDateTime​(java.time.Instant updatedDateTime)
    Sets the date/time when the object was last updated in the database.
    java.lang.String toJson()  

    Methods inherited from class java.lang.Object

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

    • DefaultBaseEntity

      protected DefaultBaseEntity()
  • Method Details

    • getId

      public java.util.UUID getId()
      Returns the ID of the object.
      Specified by:
      getId in interface BaseEntity
      Returns:
    • setId

      public void setId​(java.util.UUID id)
      Sets the ID of the object.
      Specified by:
      setId in interface BaseEntity
      Parameters:
      id -
    • getCreatedDateTime

      public java.time.Instant getCreatedDateTime()
      Returns the date/time when the object was created in the database.
      Specified by:
      getCreatedDateTime in interface BaseEntity
      Returns:
      The created date/time.
    • setCreatedDateTime

      public void setCreatedDateTime​(java.time.Instant createdDateTime)
      Sets the date/time when the object was created in the database.
      Parameters:
      createdDateTime - The created date/time.
    • getUpdatedDateTime

      public java.time.Instant getUpdatedDateTime()
      Returns the date/time when the object was last updated in the database.
      Specified by:
      getUpdatedDateTime in interface BaseEntity
      Returns:
      The updated date/time.
    • setUpdatedDateTime

      public void setUpdatedDateTime​(java.time.Instant updatedDateTime)
      Sets the date/time when the object was last updated in the database.
      Parameters:
      updatedDateTime - The updated date/time.
    • isDeleted

      public boolean isDeleted()
      Returns whether the object is deleted. Data is never truly deleted from the database. It is the responsibility of all application logic to enforce the deleted flag as appropriate.
      Specified by:
      isDeleted in interface BaseEntity
      Returns:
      True if the object is deleted.
    • setDeleted

      public void setDeleted​(boolean deleted)
      Marks the entity as deleted. Shortcut for setDeletedDateTime(Instant.now()).
      Specified by:
      setDeleted in interface BaseEntity
      Parameters:
      deleted - True if the object is deleted.
    • getDeletedDateTime

      public java.time.Instant getDeletedDateTime()
      Returns the date/time when the object was last deleted in the database. Data is never truly deleted from the database. It is the responsibility of all application logic to enforce the deleted flag as appropriate.
      Specified by:
      getDeletedDateTime in interface BaseEntity
      Returns:
      The deleted date/time.
    • onPrePersist

      public void onPrePersist()
    • onPreUpdate

      public void onPreUpdate()
    • hashCode

      public int hashCode()
      Returns a hash code for this details object. The hash code is completely based on the ID. If a deriving class expects to mix/match several classes within a hash table, then you should override and replace this.
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Determines if this object equals another. Equality is defined as same class type and same ID.
      Overrides:
      equals in class java.lang.Object
    • toJson

      public java.lang.String toJson()
    • fromJson

      public static <T extends DefaultBaseEntity> T fromJson​(java.lang.Class<T> c, java.lang.String str)
    • copyNonNullProperties

      public <T extends DefaultBaseEntity> void copyNonNullProperties​(T other)
      Copies all non-null properties from the other object to this object.
      Parameters:
      other - The other entity.