Enterprise Java Development@TOPIC@

Chapter 58. Relationship Capabilities

58.1. Fetching
58.1.1. fetch=LAZY
58.1.2. fetch=EAGER
58.2. Cascades
58.3. Orphan Removal
58.4. Summary

  • @XxxToXxx Relationship annotated with fetch=LAZY property


  • Parent accessed, debug printed, and then child collection accessed


  • Debug for parent printed before child rows retrieved

  • Child rows retrieved when parent collection accessed



  • Same as fetch=LAZY case


  • Child objects fetched with parent

  • Access to child collection occurs after all children fetched


PERSIST

Related entities persisted when this entity is passed to em.persist()

DETACH

Related entities detached from persistence unit when this entity passed to em.detach()

REMOVE

Related entities deleted from database when this entity passed to em.remove()

REFRESH

Related entities refreshed with state of database when this entity passed to em.refresh()

MERGE

Related entities update state of database when this entity is passed to em.merge()




  1. Attendee.residence_id set to null

  2. Orphaned residence deleted