When given a hierarchical business object, the create operation
recursively traverses the business object, creating rows corresponding to
each table.
Here are the details:
- The create operation recursively inserts each single-cardinality child
business object contained with ownership into the database. In other words,
the adapter creates the child and all child business objects that the child
and its children contain.
If the business object definition specifies that
an attribute represents a child business object with single cardinality and
that attribute is empty, the adapter ignores the attribute. However, if the
business object definition requires that the attribute represent a child,
and it does not, the adapter returns an error and stops processing.
- The create operation retrieves and checks the existence of each single-cardinality
child business object contained without ownership. If the retrieve operation
is unsuccessful, indicating that the child does not exist in the database,
the adapter returns an error and stops processing. If the retrieve operation
is successful, the adapter recursively updates the child business object.
Note: For this approach to work correctly when the child business object
exists in the application database, primary key attributes in child business
objects must be cross-referenced correctly on create operations. If the child
business object does not exist in the application database, the primary key
attributes must not be set.
- It inserts the top-level business object in the database as follows:
- It sets each of its foreign key values to the primary key values of the
corresponding child business object represented with single cardinality. Because
values in child business objects can be set by database sequences or counters
or by the database itself during the creation of the child, this step ensures
that the foreign key values in the parent are correct before
the adapter inserts the parent in the database.
- It generates a new, unique ID value for each attribute that is set automatically
by the database. The name of the database sequence or counter is stored in
the attribute’s application-specific information. If an attribute has an associated
database sequence or counter, the value generated by the adapter overwrites
any value passed in by the application server. For more information on specifying
a database sequence or counter, see UID=AUTO in "Application-specific
information for simple attributes."
- It inserts the top-level business object into the database.
- It processes each of its multiple-cardinality child business objects as
follows:
- It sets the foreign key values in each child to reference the value in
the corresponding primary key attributes in the parent. Because the parent’s
primary key values might have been generated during the creation of the parent,
this ensures that the foreign-key values in each child are correct before
the adapter inserts the child into the database.
- It inserts each of its multiple-cardinality child business objects into
the database.