@ElementCollection :
@Embeddable
cannot be queried,
does not have ID,
no version,
no reverse pointer...
http://en.wikibooks.org/wiki/Java_Persistence/ElementCollection
@ManyToOne
@ManyToMany
Bi-directional relationship:
each entity has a relationship field or property that refers to the other entity
owning side
determines how the runtime makes updates to the relationship in the database
is
the "many" side of "many-to-one" bi-directional is always the owning side
in "one-to-one", the owning side contains the foreign key property
in "many-to-many", either side can be the owning side
inverse side
must use mappedBy element of the relationship annotation (such as @OneToMany) to designate the property or field in the owning entity
is never the "many" side of "many-to-one"; "many" side is always the owning side
Uni-directional: only has owning side
direction in relationship also determine if query can navigate from one entity to another
(when one entity.... related entity also...):
ALL = all
DETACH : detach from persistence context
MERGE : merge into persistence context
PERSIST : persist into persistence context
REFRESH : refresh in persistence context
REMOVE : remove from persistence context
Use in @OneToOne or @OneToMany
Use orphanRemoval = "true" in @OneToOne or @OneToMany to specify removal of a child if the child is removed from the collection