Package org.minijax.dao
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 protectedDefaultBaseEntity() -
Method Summary
Modifier and Type Method Description <T extends DefaultBaseEntity>
voidcopyNonNullProperties(T other)Copies all non-null properties from the other object to this object.booleanequals(java.lang.Object obj)Determines if this object equals another.static <T extends DefaultBaseEntity>
TfromJson(java.lang.Class<T> c, java.lang.String str)java.time.InstantgetCreatedDateTime()Returns the date/time when the object was created in the database.java.time.InstantgetDeletedDateTime()Returns the date/time when the object was last deleted in the database.java.util.UUIDgetId()Returns the ID of the object.java.time.InstantgetUpdatedDateTime()Returns the date/time when the object was last updated in the database.inthashCode()Returns a hash code for this details object.booleanisDeleted()Returns whether the object is deleted.voidonPrePersist()voidonPreUpdate()voidsetCreatedDateTime(java.time.Instant createdDateTime)Sets the date/time when the object was created in the database.voidsetDeleted(boolean deleted)Marks the entity as deleted.voidsetId(java.util.UUID id)Sets the ID of the object.voidsetUpdatedDateTime(java.time.Instant updatedDateTime)Sets the date/time when the object was last updated in the database.java.lang.StringtoJson()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:
getIdin interfaceBaseEntity- Returns:
-
setId
public void setId(java.util.UUID id)Sets the ID of the object.- Specified by:
setIdin interfaceBaseEntity- Parameters:
id-
-
getCreatedDateTime
public java.time.Instant getCreatedDateTime()Returns the date/time when the object was created in the database.- Specified by:
getCreatedDateTimein interfaceBaseEntity- 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:
getUpdatedDateTimein interfaceBaseEntity- 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:
isDeletedin interfaceBaseEntity- Returns:
- True if the object is deleted.
-
setDeleted
public void setDeleted(boolean deleted)Marks the entity as deleted. Shortcut forsetDeletedDateTime(Instant.now()).- Specified by:
setDeletedin interfaceBaseEntity- 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:
getDeletedDateTimein interfaceBaseEntity- 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:
hashCodein classjava.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:
equalsin classjava.lang.Object
-
toJson
public java.lang.String toJson() -
fromJson
-
copyNonNullProperties
Copies all non-null properties from the other object to this object.- Parameters:
other- The other entity.
-