New Issues
Let’s learn about some of the new issues that we may face in the bidirectional application.
We'll cover the following
Issues to deal with
Compared to the Unidirectional Association App, we have to deal with a few new technical issues:
- We define the derived inverse reference properties, such as
Publisher::/publishedBooks
, without a check operation and without a set operation. - We also need to maintain the derived inverse reference properties by maintaining the derived (sets of) inverse references that form the collection value of a derived inverse reference property. In particular, this requires that:
- Whenever the value of a single-valued leader reference property is initialized or updated with the help of a setter (a reference is assigned to a
Publisher
instancep
tob.publisher
for a Book instanceb
), an inverse reference has to be assigned or added to the corresponding value of the derived inverse reference property. For example, ifb
is added top.publishedBooks
. When the value of the leader reference property is updated and the derived inverse reference property is multi-valued, then the obsolete inverse reference to the previous value of the single-valued leader reference property needs to be deleted. - Whenever the value of an optional single-valued leader reference property is unset (we assign
null
tob.publisher
for aBook
instanceb
), the inverse reference needs to be removed from the corresponding value of the derived inverse reference property. For example, ifb
is removed fromp.publishedBooks
. This is done if the derived inverse reference property is multivalued. Otherwise, the corresponding value of the derived inverse reference property needs to be unset or updated. - Whenever a reference is added to the value of a multivalued leader reference property with the help of an
add
method (add anAuthor
referencea
tob.authors
for aBook
instanceb
), an inverse reference has to be assigned or added to the corresponding value of the derived inverse reference property. For example, ifb
is added toa.authoredBooks
. - Whenever a reference is removed from the value of a multivalued leader reference property with the help of a
remove
method (remove a reference to anAuthor
instancea
fromb.authors
for a Book instanceb
), the inverse reference needs to be removed from the corresponding value of the derived inverse reference property. For example, ifb
is removed froma.authoredBooks
. This is done if the derived inverse reference property is multivalued. Otherwise, the corresponding value of the derived inverse reference property needs to be either unset or updated. - Whenever an object with a single reference or with multiple references as the value of a leader reference property is destroyed (when a
Book
instanceb
with a single referenceb.publisher
to a Publisher instancep
is destroyed), the derived inverse references have to be removed first. For example, ifb
is removed fromp.publishedBooks
.
- Whenever the value of a single-valued leader reference property is initialized or updated with the help of a setter (a reference is assigned to a
When a new object is created with a one or more references as the value of a leader reference property, such as a new Book
instance b
with a single reference b.publisher
, its setter or add method is invoked and takes care of the creation of derived inverse references.
Get hands-on with 1200+ tech skills courses.