liveBook · Manning

Lifecycle dependency

As explained in Java Persistence with Spring Data and Hibernate epub

A lifecycle dependency is a dependency in which the existence or removal of one object governs the existence or removal of another object.

A lifecycle dependency exists when one object governs the existence or removal of another. The dependent object belongs to the owner’s composition and cannot meaningfully exist alone. section 5.1.3

This distinction guides persistence mapping. A fully dependent object is usually a value type: it has no independent identity, cannot be shared, and follows the owner through saving, updating, and removal. An entity may still have a dependent lifecycle when future shared references require its own identity. section 5.1.3 section 8.3

Use these distinctions when choosing a mapping:

  • Map a component as a value type when one owner exclusively controls it and it has no independent identity. section 5.1.3
  • Treat a child as an entity when shared references may arise, even if its lifecycle remains dependent on the parent. section 5.1.3
  • Distinguish lifecycle dependency from an ordinary entity association: associated entities can be saved, updated, or removed independently unless finer-grained rules are configured. section 8.3

Auction domain

An Item owns its Bid instances through composition, so removing the item removes its bids. If users later expose a collection of their bids, Bid gains shared references and needs entity identity while retaining a dependent lifecycle. Address remains a value type because one User exclusively owns it. section 5.1.3

Parent with images

An Item can own a collection of Image value types. The images are saved, updated, and removed with the Item, never independently; removing the Item also removes the image collection. section 8.3

Figure 5.4 Diagramming stereotypes for entities and value types

Use the entity-and-value-type diagram to compare independent identity with composition-controlled lifecycles. section 5.1.3

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains ownership, identity, shared references, and save-update-remove behavior, but defers detailed association configuration.
Examples
Uses User-Address, Item-Bid, and Item-Image models to contrast exclusive ownership, shared references, and independent associations.
What it assumes
Assumes object-oriented classes and associations while introducing identity, composition, value types, and entity lifecycles.
What you can do after
Evaluate whether a persistent class should remain a value type or become an entity with identity.
How it connects
Connects composition with value types, entities, parent-child relationships, and entity 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.