4.2.2.2. One-to-Many: Two Levels of Nesting
Composition can be deeper, with up to two nested levels. Let’s extend the previous example by adding a MeetingPoint
entity describing a meeting point at an airport terminal:
The Terminal
entity contains the meetingPoints
attribute – a collection of the MeetingPoint
instances. In order for all three entities to become a single composition and be edited together, the following should be done in addition to the steps described above:
-
Terminal.java - the
meetingPoints
attribute of theTerminal
class is marked as@Composition
and@OnDelete
similarly to theterminals
attribute of theAirport
class. -
views.xml - the
terminal-meetingPoints-view
view of theTerminal
class contains themeetingPoints
collection attribute. This view is used in theairport-terminals-meetingPoints-view
view of theAirport
entity. -
airport-edit.xml - the
Airport
edit screen XML descriptor contains datasources for an instance of theAirport
and nested entities for the entire composition (airportDs
>terminalsDs
>meetingPointsDs
).WarningHere, the
meetingPointsDs
datasource is not associated with any visual components, however it is needed for correct operation of joint editing of the composition. -
terminal-edit.xml - the terminal edit screen XML descriptor contains a nested datasource and a corresponding table for the
meetingPoints
collection.
As a result, the updated instances of the MeetingPoint
, as well as the Terminal
instances, will be saved to the database only with the Airport
instance in the same transaction.