- A relationship is a reference from one object to another.
- In Java, relationships are defined through object references (pointers) from a source object to the target object.
- In a relational database relationships are defined through foreign keys. The source row contains the primary key of the target row to define the relationship (and sometimes the inverse). A query must be performed to read the target objects of the relationship using the foreign key and primary key information.
- In Java, if a relationship is to a collection of other objects, a
Collectionor array type is used in Java to hold the contents of the relationship. In a relational database, collection relations are either defined by the target objects having a foreign key back to the source object's primary key, or by having an intermediate join table to store the relationship (both objects' primary keys).
JPA Relationship Types
- OneToOne - A unique reference from one object to another, inverse of a
OneToOne. - ManyToOne - A reference from one object to another, inverse of a
OneToMany. - OneToMany - A
CollectionorMapof objects, inverse of aManyToOne. - ManyToMany - A
CollectionorMapof objects, inverse of aManyToMany. - Embedded - A reference to a object that shares the same table of the parent.
- ElementCollection - JPA 2.0, a
CollectionorMapofBasicorEmbedableobjects, stored in a separate table.

No comments:
Post a Comment