liveBook · Manning

Association

As explained in Java Persistence with Spring Data and Hibernate epub

An association is a relationship connecting two model elements and allowing navigation between them.

An association connects two model elements and permits navigation between them. In Java, object references express the relationship; in a relational database, foreign-key columns store copied key values and enforce referential integrity. section 1.2.4

Model an association by making its navigation, multiplicity, and lifecycle semantics explicit:

  • Direction matters in the object model: bidirectional navigation requires a reference or collection on both associated classes. section 1.2.4
  • Multiplicity distinguishes many-to-one, one-to-many, and many-to-many relationships; relational many-to-many mappings generally require a link table. section 1.2.4 section 8.3
  • Lifecycle semantics separate independent entity associations from aggregation or composition, where the part may depend on the whole. section 6.2 section 8.3

User and BillingDetails

A Java model can expose User.billingDetails as a Set<BillingDetails> and BillingDetails.user as a back-reference. A relational schema can represent the same relationship with BILLINGDETAILS.USERNAME referencing USERS.USERNAME. If the relationship becomes many-to-many, introduce USER_BILLINGDETAILS with a composite primary key and two foreign keys. section 1.2 section 1.2.4

Figure 1.4 One-to-many association between User and BillingDetails

Use the one-to-many diagram to compare the navigable Java relationship with its associated domain elements. section 1.2.4

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Defines direction, multiplicity, foreign keys, link tables, and lifecycle dependency, while deferring detailed framework mappings to later treatments.
Examples
Uses User, BillingDetails, Address, Item, and Bid models plus Java collections, SQL foreign keys, diagrams, and a many-to-many link table.
What you can do after
Evaluate association mappings by navigation direction, multiplicity, lifecycle dependency, and relational representation.
How it connects
Connects object references with foreign keys, entity identity, value types, composition, multiplicity, ORM, JPA, and Spring Data JDBC.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.