Class TimestampedJpaEntity<ID>

java.lang.Object
com.reallifedeveloper.common.infrastructure.persistence.BaseJpaEntity<ID>
com.reallifedeveloper.common.infrastructure.persistence.TimestampedJpaEntity<ID>
Type Parameters:
ID - the type of the primary key

@MappedSuperclass public class TimestampedJpaEntity<ID> extends BaseJpaEntity<ID>
A base class for JPA entities that need to keep track of when they where created and when they were last updated.
Author:
RealLifeDeveloper
  • Constructor Details

    • TimestampedJpaEntity

      protected TimestampedJpaEntity()
      Creates a new AbstractTimestampedJpaEntity with null ID and with the created and updated timestamps also set to null.

      This constructor should normally only be used by Hibernate, and you are encouraged to create a no-argument package private constructor in your entities that call this.

    • TimestampedJpaEntity

      protected TimestampedJpaEntity(ID id)
      Creates a new AbstractTimestampedJpaEntity with the given ID and with the created and updated timestamps set to the current time.
      Parameters:
      id - the ID of the new entity
    • TimestampedJpaEntity

      protected TimestampedJpaEntity(ID id, ZonedDateTime created, ZonedDateTime updated)
      Creates a new AbstractTimestampedJpaEntity with the given ID and timestamps.
      Parameters:
      id - the ID of the new entity
      created - the time and date the entity was created
      updated - the time and date the entity was last updated
      Throws:
      IllegalArgumentException - if created or update is null
  • Method Details

    • created

      public Optional<ZonedDateTime> created()
      Gives the time and date that the entity was created.
      Returns:
      the timestamp of creation
    • updated

      public Optional<ZonedDateTime> updated()
      Gives the time and date that the entity was last updated.
      Returns:
      the timestamp of last update
    • setUpdated

      public void setUpdated(ZonedDateTime updated)
      Sets the time and date that the entity was last updated.
      Parameters:
      updated - the timestamp of last update
      Throws:
      IllegalArgumentException - if updated is null