Annotated with @Entity
have a public / protected no-arg constructor
not "final", no persistent field getter "final"
implements "Serializable" interface if to be passed by value as detached object
Entity may extend entity / non-entity classes
implements equals() / hashCode() if to be put into set; base on business key is good idea (based on Hibernate tutorial)
May be primitive, String, other Serializable, Enumerated, other entities, collection of entities, embedded classes
May be field or property (getter)
@Transient or mark "transient" - non-persistent field / property
Set : @ElementCollection(target = class, fetch=LAZY|EAGER)
Map :
Key
is basic type, use @MapKeyColumn, conventional name is {property_name}_KEY
if generic type not used, use @MapKeyClass
if key is primary key or a property of the value entity, use @MapKey
Value
value is basic type or embedded class: @ElementCollection
value is entity, use @OneToMany or @ManyToMany
or @JohnColumn if unidirectional one-to-many relationship
use Map on only one side of bi-directional relationship
Upon PrePersist, PreUpdate and PreRemove lifecycle events, bean validation will be performed.
Simple PK
@Id
Composite PK
@EmbeddedId or @IdClass
@Embeddable - a class to be embedded in another
@Embedded (optional) - think about how to represent null! look here: https://stackoverflow.com/questions/2838528/hibernate-does-not-allow-an-embedded-object-with-an-int-field-to-be-null