Class TimestampedEntity<I extends Comparable<I> & Serializable>

Type Parameters:
I - The generic ID type.
All Implemented Interfaces:
Serializable, Comparable<BaseEntity<I>>, Identifiable<I>, Timestamped
Direct Known Subclasses:
VersionedEntity

@MappedSuperclass public abstract class TimestampedEntity<I extends Comparable<I> & Serializable> extends GeneratedIdEntity<I> implements Timestamped

Mapped superclass for timestamped entity. It extends from GeneratedIdEntity which in turn extends from BaseEntity. In addition to the "id" column, it specifies two timestamp columns, named "created" and "lastModified". On pre persist, the both columns will be set to current timestamp. On pre update, the "lastModified" column will be set to current timestamp, unless skipAdjustLastModified() is called beforehand.

Author:
Bauke Scholtz
See Also:
  • Constructor Details

    • TimestampedEntity

      public TimestampedEntity()
  • Method Details

    • onPrePersist

      public void onPrePersist()
    • onPreUpdate

      public void onPreUpdate()
    • skipAdjustLastModified

      public void skipAdjustLastModified()
      Invoke this method if you need to skip adjusting the "last modified" timestamp during any update event on this instance. In case you intend to reset this later on, simply obtain a new instance from the entity manager.
    • setCreated

      public void setCreated(Instant created)
      Specified by:
      setCreated in interface Timestamped
    • getCreated

      public Instant getCreated()
      Specified by:
      getCreated in interface Timestamped
    • setLastModified

      public void setLastModified(Instant lastModified)
      Specified by:
      setLastModified in interface Timestamped
    • getLastModified

      public Instant getLastModified()
      Specified by:
      getLastModified in interface Timestamped