liveBook · Manning

Shared reference

As explained in Java Persistence with Spring Data and Hibernate epub

A shared reference is a situation in which multiple object instances can reference the same referenced object instance.

A shared reference occurs when multiple object instances reference the same referenced object instance. It usually signals that the referenced class needs entity identity and an independent or potentially shared lifecycle, rather than value-type treatment. section 5.1.3 section 9.1

Use lifecycle and reference structure to distinguish shared entities from dependent value types:

  • Treat a class as an entity when instances have their own identity, receive references from multiple instances, and can outlive individual references. section 5.1.3
  • Treat a class as a value type when one owning instance fully controls its lifecycle and no other instance can reference it. section 5.1.3
  • Reclassify a dependent object as an entity when a later association creates shared references, even if its lifecycle remains dependent. section 5.1.3

An address shared by users and shipments

A User may reference an Address as shippingAddress, while a Shipment also references that same Address instance. This makes Address an entity with its own identity instead of an embeddable component. By contrast, billingAddress, homeAddress, and shippingAddress are often modeled as an embeddable component when each address belongs exclusively to one User. section 9.1

Figure 5.4 Diagramming stereotypes for entities and value types

Use the entity/value-type diagram to inspect how stereotypes, ownership, identity, and shared references influence persistent-class design. section 5.1.3

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains shared references through identity, lifecycle, composition, and one-to-one mapping consequences.
Examples
Uses User, Address, Shipment, and Bid examples to contrast exclusive ownership with shared entity references.
What it assumes
Assumes basic object modeling, UML associations, composition, and persistent-class distinctions.
What you can do after
Evaluate whether a class needs identity and entity mapping when additional associations create shared references.
How it connects
Connects shared references with entities, value types, composition, identity, lifecycle, and one-to-one associations.

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.