Class DefaultBaseEntity

  • All Implemented Interfaces:
    Serializable, BaseEntity
    Direct Known Subclasses:
    DefaultNamedEntity

    @MappedSuperclass
    public abstract class DefaultBaseEntity
    extends 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 Detail

      • DefaultBaseEntity

        protected DefaultBaseEntity()
    • Method Detail

      • getId

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

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

        public 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​(Instant createdDateTime)
        Sets the date/time when the object was created in the database.
        Parameters:
        createdDateTime - The created date/time.
      • getUpdatedDateTime

        public 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​(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 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 Object
      • equals

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

        public String toJson()
      • 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.