liveBook · Manning

Edge

As explained in Spring in Action, Sixth Edition

An entity relationship is an association between persisted domain entities represented in an application's data model.

An edge represents an association between persisted domain entities. In reactive R2DBC persistence, model that association explicitly because direct entity relationships are not automatically supported. section 13.1.1

Represent an edge by choosing one of these persistence strategies:

  • Store identifiers such as Set<Long> values in the owning entity; this preserves uniqueness but may require an array column and cannot always enforce foreign keys. section 13.1.1
  • Shape the entities and tables to mirror the relationship, using a column on the referred object to point back to its owner. section 13.1.1
  • Serialize related entities as JSON in a large VARCHAR column when querying through the relationship is unnecessary. section 13.1.1

Taco ingredients

A Taco keeps ingredientIds in a HashSet<Long> and adds an ingredient by storing its ID. A TacoOrder similarly keeps taco IDs, separating relationship persistence from the related objects themselves.

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains relationship-storage alternatives and their trade-offs, but stops short of implementing relationship loading.
Examples
Uses Taco ingredient IDs and TacoOrder taco IDs stored in sets and database array columns.
What it assumes
Assumes persisted entities and database tables, while introducing R2DBC's lack of direct entity relationships.
What you can do after
Apply it via Spring Data R2DBC by choosing an explicit storage strategy for related entity identifiers.
How it connects
Connects domain entities with persistence, foreign keys, arrays, JSON, and Spring Data R2DBC.

Also explained in

Compare how 18 books explain edge →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.