Using Inverse Reference Properties

An inverse property is one in which two objects reference each other. One end of this inverse reference property can be automatic; that is, the JADE Object Manager establishes the return reference for you.

For example, if you have two classes called Driver and Car, if the Driver class contains a property myCar, the inverse of that property could be the property myDriver in the Car class. Inverse reference properties can be:

Reference Usage
one-to-one myDept of Manager = myManager of Department
  In this example:
 
  • myDept is a property of type Department in the Manager class

 
  • myManager is a property of type Manager in the Department class

one-to-many allEmployees of Department = myDept of Employee
  In this example:
 
  • allEmployees is a set with membership of Employee objects in the Department class

 
  • myDept is a property of type Department in the Employee class

many-to-many allMailGroups of Employee = allMembers of MailGroup
  In this example:
 
  • allMailGroups is a collection containing MailGroup objects in the Employee class

 
  • allMembers is a collection containing Employee objects in the MailGroup class

For inverse reference properties, you must specify one of the update modes listed in the following table.

Mode Description
Automatic The property cannot be updated in user logic but is automatically maintained by the system in response to the user updating the inverse or deleting the parent of the inverse.
Manual / Automatic Either the property being maintained or the inverse can be updated in user logic. The other side of the reference is automatically maintained by the system.
Manual The property being maintained is always updated in user logic, except when the parent object of the inverse is deleted. The inverse is always maintained by the system.

A reference property is a one relationship and a collection property is a many relationship. If a property defining the relationship is not a collection, only one reference is allowed. The collection can be a set or a dictionary.

To add the same property on both sides of an inverse relationship:

  1. The relationship type must be peer-to-peer.

  2. The update mode must be Manual / Automatic.

  3. The relationship must be one-to-one or many-to-many.

Only dictionaries with member keys can be used to define relationships.

Mapped properties (that is, properties that have a mapping method) from a RootSchema class cannot be used as dictionary keys.

A reference on a class can have itself as an inverse reference if the inverse is defined as a peer-to-peer relationship, the update mode is Manual / Automatic, and the reference is one-to-one or many-to-many. Applications that require two objects of the same class can therefore have a reference between themselves so they can use the same myObject reference with the inverse being the myObject reference (for example, in a double-ledger accounting system with two equal and opposite transactions so that you do not have to define two attributes so that you can define the inverse reference).

For more details, see "Automatic Key Maintenance" and "Resolving Exceptions", under "Maintaining Dictionary Key Paths", in Chapter 3.

For details about using constraints to maintain automatic inverse references when the specified conditions are satisfied, see "Defining and Compiling JADE Methods and Conditions" and "Adding Conditions to Classes or Primitive Types", earlier in this chapter.