4.2.2.4. One-to-One Composition

The one-to-one composition will be illustrated by the Customer and CustomerDetails entities:

composition recipe 3
  • Customer.java - the Customer entity contains an optional link to CustomerDetails annotated with @Composition.

  • CustomerDetails.java - the CustomerDetails entity.

  • customer-edit.xml - the customer edit screen descriptor. It contains a nested datasource for the CustomerDetails instance. In order to load the nested instance, the root datasource uses a view of the Customer entity that includes the details attribute. The field group in the customer edit screen just declares a field for the details attribute.

As a result, customer editing works as follows:

composition recipe oto 1
  • When the open action is invoked, a new instance of CustomerDetails is created and its edit screen is shown. When OK is clicked in the details editor, the details instance is not saved to the database, but to the detailsDs datasource of the customer edit screen.

  • The picker field displays the instance name of the details entity:

composition recipe oto 2
  • When a user clicks OK in the customer edit screen, the updated Customer instance together with the CustomerDetails instance is submitted to the DataManager.commit() method on the Middleware and saved to the database within a single transaction.

  • If the user invokes the clear action of the picker field, the CustomerDetails instance is deleted and the reference to it is cleared in the same transaction after the user commits the customer editor.