Skip to main content

Adding Child Objects

Within the child class (or many-side) of a relationship, Caché represents the parent (or one-side) as a simple property of the parent (or one-side) type. So, for example, each PhoneNumber object contains a property of type Contact that represents its parent object. The property projects to Java as its Java projection type. The getContact method of the PhoneNumber projection returns an object of the Contact projection type.

The following Java client method creates a PhoneNumber object and uses its setContact method to set the parent object.


public class BindingExamples {
   public static void addNumberToContact(Database db, String number,
      String type, Contact contact)throws CacheException {
      PhoneNumber phoneNumber = new PhoneNumber(db);
      phoneNumber.setNumber(number);
      phoneNumber.setPhoneNumberType(type);
      phoneNumber.setContact(contact);
      phoneNumber.save();
   }
}
FeedbackOpens in a new tab