Entity initialization from an event
You can initialize entities when you need them, at the reception of a first event that references these entities. Use the business rule language in the business model statements tab to declare the initialization of an entity from an event.
In the statement, you specify the entity that you want to initialize and the event that initializes it:

- The bound entity type.
- The event type that is processed.
- The bound entity.
- The expression to retrieve the identifier that corresponds to the bound entity in the event.
- Optional: the initialization of the attributes of the bound entity.
- Optional: the mapping of the attributes to the event type.
- Specify attributes for the bound entity.
- Send an event as a result of the initialization of the bound entity.
You can also initialize entities from an external data source by using an entity initialization extension based on Java™. For more information, see Creating entity initialization extensions
Examples
In this example, an account entity is initialized
when a customer opens a bank account. The credit limit and the customer
of this account are defined in the action part of the rule. Additionally,
the initialized account entity
is added to the entities of the customer remote
entity. Here, the customer entity
is defined in the business model as a business entity identified by
a name and related to some accounts.
an account is initialized from an open account event, where this account comes from the account of this open account event:
- set the credit limit of this account to the limit of this open account event
- set the customer of this account to the customer of this open account event
- add this account to the accounts of the customer of this open account event.In
the following example, a customer entity
is initialized when a new customer
event occurs, where this event is defined in the business
model as a business event that has a name. The action part of the
rule specifies that this initialization triggers a new open account event, which
is related to the customer entity, and with a credit limit of 10,000.
a customer is initialized from a new customer event, where this customer comes from the name of this new customer event:
- emit a new open account event where the customer is this customer, the limit is 10,000 .In
the following example, an account entity
is initialized with no action.
an account is initialized from an open account event, where this account comes from the account of this open account event.Entity initialization on a hierarchy of entity and event types
When two or more initializers are declared on a hierarchy of entity types, their priority is based on this hierarchy. The priority is given to the most general entity type.
Example 1
The following business model defines
a vehicle, a car, a vehicle activity, and a car activity. The car entity type is a specialization
of the vehicle entity
type, and a car activity event
type is a specialization of the vehicle
activity event type.
a vehicle is a business entity identified by a vehicle id ( text ).
a car is a vehicle.
a car has a passenger capacity ( integer ).
a vehicle activity is a business event time-stamped by an event timestamp ( date & time ).
a vehicle activity is related to a vehicle.
a car activity is a vehicle activity. The following
initializations can be declared in the business model statements,
where the same entity type can be initialized by two different event
types. Here, the first initialization statement has a higher priority
because the vehicle activity event
type that triggers the initialization is more general than the car activity event type.
a vehicle is initialized from a vehicle activity, where this vehicle comes from the vehicle of this vehicle activity.
a vehicle is initialized from a car activity, where this vehicle comes from the vehicle of this car activity. Example 2
Consider a hierarchy of business entities, a hierarchy of business events, and two initializers for the entity types.
Business model definitions:
a vehicle is a business entity identified by a vehicle id ( text ).
a car is a vehicle.
a car has a cost (numeric).
a leased car is a car.
a leased car has a monthly payment (numeric).
a car acquisition is a business event.
a car acquisition is related to a vehicle.
a car acquisition has an price (numeric).
a car leasing is a car acquisition.
a car leasing has a duration in months (numeric).
a car leasing has an initial payment (numeric).
a car leasing has a monthly payment (numeric).Business model statements:
a car is initialized from a car acquisition , where this car comes from the vehicle of this car acquisition:
- set the cost of this car to the price of this car acquisition.
a leased car is initialized from a car leasing , where this leased car comes from the vehicle of this car leasing:
- set the monthly payment of this leased car to the monthly payment of this car leasing
- set the cost of this leased car to the initial payment of this car leasing +
the monthly payment of this car leasing * the duration in months of this car leasing.The
first initializer processes events of type car acquisition, and initializes
entities of type car.
The second initializer processes events of type car leasing and initializes entities
of type leased car.
Consider
an event E1 that is an instance of type car leasing and that is related
to a non-created vehicle entity.
The leased car initializer can initialize this entity. The type car leasing is a subtype of car acquisition, so the event
is also an instance of type car
acquisition. As a consequence, the car initializer is also
able to initialize the non-created vehicle entity
of the event. In this context, the vehicle entity
is an instance of type leased car and
an instance of type car.
The type leased car is
the most-specific of these types. The runtime system will therefore instantiate
the type leased car when creating
a vehicle entity of event
E1. Then, this newly created entity is initialized by the leased car
initializer and by the car initializer which both process the event
E1. The first initializer sets the monthly payment and the cost of
the entity, and the second initializer extends the cost of the leased
car to the price of the event.