I
- The generic ID type, usually Long
.@MappedSuperclass public abstract class BaseEntity<I extends Comparable<I> & Serializable> extends Object implements Comparable<BaseEntity<I>>, Identifiable<I>, Serializable
Let all your entities extend from this. Then you can make use of BaseEntityService
. This mapped superclass
already automatically takes care of the id
column.
There are two more mapped superclasses which may also be of interest.
TimestampedEntity
- extends BaseEntity
with created
and lastModified
columns and automatically takes care of them.
VersionedEntity
- extends TimestampedEntity
with a @Version
column.
ID
Constructor and Description |
---|
BaseEntity() |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(BaseEntity<I> other)
Orders by default with "nulls last".
|
boolean |
equals(Object other)
Compares by default by entity class (proxies taken into account) and ID.
|
I |
getId()
Returns the ID.
|
int |
hashCode()
Hashes by default the classname and ID.
|
void |
setId(I id)
Sets the ID.
|
String |
toString()
The default format is
ClassName[id={id}] . |
public I getId()
Identifiable
getId
in interface Identifiable<I extends Comparable<I> & Serializable>
public void setId(I id)
Identifiable
setId
in interface Identifiable<I extends Comparable<I> & Serializable>
id
- The ID.public int hashCode()
public boolean equals(Object other)
public int compareTo(BaseEntity<I> other)
compareTo
in interface Comparable<BaseEntity<I extends Comparable<I> & Serializable>>
Copyright © 2015–2017 OmniFaces. All rights reserved.