skip to main content
Corticon Studio: Rule Modeling Guide : Writing Rules to access external data : Inserting new records in a middle table
 

Try Corticon Now

Inserting new records in a middle table

In relational databases, many-to-many relationships are modeled using a “middle” table (also known as an “intersection” table). Assume we have two tables named A and B, and they have a many-to-many relationship. A third or “middle” table named AB has a many-to-1 relationship with both A and B.
A many-to-many Association between two Entities in the Vocabulary can be mapped to such a middle table. Therefore, table AB does not need to correspond to a specific Entity in the Vocabulary. However, should the middle table contain additional business fields, then it must have a corresponding Entity in the Vocabulary. In such a situation, attempting to create a new record/row in table AB using rules may run into limitations depending on:
*the cardinalities of the associations between AB and A, and AB and B
*the identity strategy used for A, B, and AB.
The table below highlights known limitations for combinations of entity identity (Application or Datastore) and association directionality (bidirectional or unidirectional):
* If com.corticon.reactor.engine.NoSyncAssoc property value is true, the order in which the association role assignments appear in the .new[…] operator may result in a situation where things appear to work but, in fact, the middle table is not updated properly in the database. This configuration should be avoided if Application Identity is used.

Performance Degrades when Updating “Middle Tables”

By default, Corticon synchronizes all instances of an association with the database prior to modifying it. In some situations, this may result in a large number of records being retrieved into memory unnecessarily and cause a significant performance degradation. In order to prevent unnecessary database synchronization, the value of the following property in CcStudio.properties (inside CcConfig.jar) must be set to true:
com.corticon.reactor.engine.NoSyncAssoc=true
Once this is done, Studio must be restarted and the Vocabulary and Rulesheet must be regenerated before redeploying the Rules