Class SettableIdBasedEntity<T extends org.springframework.data.domain.Persistable<Long>>

java.lang.Object
com.foreach.across.modules.hibernate.business.SettableIdBasedEntity<T>
All Implemented Interfaces:
EntityWithDto<T>, IdBasedEntity, org.springframework.data.domain.Persistable<Long>
Direct Known Subclasses:
SettableIdAuditableEntity

public abstract class SettableIdBasedEntity<T extends org.springframework.data.domain.Persistable<Long>> extends Object implements IdBasedEntity, org.springframework.data.domain.Persistable<Long>, EntityWithDto<T>
Base class for an entity with a unique long id, that allows the id to be manually set. This requires the use of a generator strategy that supports manual ids.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Two non-new entities are considered equal if they have the same id.
    Returns the id that will forcibly be assigned when persisting this entity.
    int
     
    final boolean
    Returns if the Persistable is new or was persisted already.
    abstract void
    setId(Long id)
     
    void
    setNewEntityId(Long newEntityId)
    Forcibly set the entity as new with the specific id.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.foreach.across.modules.hibernate.business.IdBasedEntity

    getId

    Methods inherited from interface org.springframework.data.domain.Persistable

    getId
  • Constructor Details

    • SettableIdBasedEntity

      public SettableIdBasedEntity()
  • Method Details

    • setId

      public abstract void setId(Long id)
    • isNew

      public final boolean isNew()
      Returns if the Persistable is new or was persisted already.
      Specified by:
      isNew in interface org.springframework.data.domain.Persistable<T extends org.springframework.data.domain.Persistable<Long>>
      Returns:
      if the object is new
    • setNewEntityId

      public void setNewEntityId(Long newEntityId)
      Forcibly set the entity as new with the specific id. When saving this instance, a new entity should be persisted with the given id.
      Parameters:
      newEntityId - id this new entity should be assigned to
    • getNewEntityId

      public Long getNewEntityId()
      Returns the id that will forcibly be assigned when persisting this entity. This method will only return a non-null call if the entity is new and not yet persisted.
      Returns:
      new entity id
      See Also:
    • toDto

      public T toDto()
      Specified by:
      toDto in interface EntityWithDto<T extends org.springframework.data.domain.Persistable<Long>>
      Returns:
      a cloned or detached version of this entity
    • equals

      public boolean equals(Object o)
      Two non-new entities are considered equal if they have the same id. New entities are only considered equal if they are in fact the same instance.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object