liveBook · Manning

HAS-A relationship

As explained in Java Persistence with Spring Data and Hibernate epub

Aggregation is an object-model relationship in which one object groups or contains another object as a constituent part.

A HAS-A relationship connects an object to something it contains or groups as a constituent part. Aggregation is one form of association; composition is stronger because the part’s lifecycle depends entirely on the whole. section 6.2

User and Address

A User can have an Address made up of street, city, state, country, and ZIP code. The address may be stored in separate columns in the USERS table, avoiding a join to retrieve it with the user. A custom SQL data type is another option, but support is poorly standardized and not portable across database products. section 1.2.1

Figure 6.1 Composition of User and Address

The diagram shows the composition relationship between User and Address. section 6.2

Object models represent both HAS-A and IS-A relationships, while SQL models represent HAS-A relationships. Mapping inheritance therefore requires strategies such as representing subclasses with foreign-key relationships and joins. section 7.0

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Defines aggregation and composition through lifecycle semantics, then compares address storage options and inheritance-mapping strategies.
Examples
Uses a User–Address model to compare embedded columns with a custom SQL data type.
What you can do after
Evaluate how a HAS-A relationship affects object lifecycle and relational storage choices.
How it connects
Links aggregation to association, composition, value types, inheritance, foreign keys, and relational mapping.

Also explained in

Compare how 2 books explain HAS-A relationship →

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.