Understanding Multi-level Insert Operations

A multi-level insert operation (or chained insert operation) allows insert operations for multiple mobile business objects that have a defined relationship during one synchronization, provided the insert operations have parameters that match the MBO relationship.

Some business processes require multiple related enterprise information system (EIS) operations, for example, creating a sales order with line items. The parent/child relationship is often represented by primary key(PK) / foreign key(FK) attributes in the parent and child MBOs. When you construct these types of MBOs in an offline client application, the PK/FK key values are transitory. When EIS operations are called to create real data, the EIS systems generate the actual key values, and the primary key of the parent is copied across to the related child MBO creation operations. These types of operations are known as "chained insert" or "multilevel insert".


Typically in a chained insert operation, you:
  1. Create the parent MBO, and indicate the attributes that constitute that MBO's primary key.
  2. Create the child MBO and draw a relationship from the parent MBO's primary key attributes to the child's foreign key attributes.

    When defining multi-level insert operations, ensure the child MBO is non-syncable, unless you are sure that the child MBO will be synced either independently, or through the parent MBO. If not, when the device application designed from these MBOs runs, the child MBOs display on the "Synchronize" screen. If the device application user invokes "Synchronize" on any of the child MBOs, a "Missing-Sync-Param" exception occurs.

  3. Define the insert operations for these two MBOs.

    The insert operation for the parent MBO must return a single row, and among the columns it must contain the primary key values. The column labels must match the attribute names of the parent MBO.

    With this information, and the relationship mapping data, Unwired WorkSpace modifies the input parameters for the insert operation of the child MBOs by replacing the foreign key attributes with the ones returned by the parent MBO's insert operation. For example:
    CREATE TABLE parent(pk int autoincrement primary key, p1 varchar(30),...)
    CREATE TABLE child(fk int references parent.pk, ...)
    The parent insert MBO is defined as:
    INSERT INTO parent(p1, ...) VALUES(?, ...); SELECT * FROM parent WHERE pk = @@IDENTITY;

    This batch query inserts the new parent row and then returns a single row containing the newly generated primary key value.

You must understand the key generation mechanism used by the EIS application from which you are developing, and be able to determine how to retrieve the newly generated keys during the insert operation (frequently, this logic is wrapped in a stored procedure).

This same technique applies to Web service, SAP, or other EIS systems, though the insert operation definitions differ.

Note:
Potential errors occur if:
Note: Unwired Server does not report the specific reason of a multilevel insert failure. If you receive errors, or if the insert fails, check each of these items to try and identify the problem.


Created September 17, 2009. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com