The Entity Engine supports an unlimited number of entity definitions spread across an unlimited number of data sources. To create a new entity, sometimes called the entity model, is simply to add the entity's definition to an entity definition file.
Make sure you have an entity definition file defined in an existing ofbiz-component.xml
file.
To create a new entity, follow these steps:
entity
elements as shown here. Please note: XML declarations shown below are for demonstration purposes only. Statements have been removed to make reading easier:<entity entity-name="EntityName" package-name="org.ofbiz.somePackageName" title="My New Entity"> <!-- Entity definition XML declaration(s) go here. Removed for demonstration purposes --> </entity>
entity
element will have one or more of the following declarations added:field
element declarations within the entity
element:<field name="someFieldName" type="any defined type"> </field>
prim-key
elements to define the primary key for this entity:<prim-key field="primaryKeyField"/>
relation
elements. entity
element with a closing tag (</entity>
).When OFBiz first starts up, it checks the data model as defined by configured entities in valid entity definition files. Any new entries in entity definition files are checked for configuration integrity and added to the OFBiz data model automatically.
The following table summarizes many common entity configuration settings:
entity element tag (Required) | ||
---|---|---|
Attribute name |
Required? |
Usage |
|
Yes |
The name used to uniquely identify this entity. |
|
No |
The equivalent database table name. If this value is the same as that of the value specified by the entity-name, then this attribute may be left out of the definition. |
|
Yes |
Used to organize entities. The suggested best practice is to use the |
To configure one or more primary keys for an entity, add an XML declaration similar to the following:
prim-key element tag (Not required) It is not required to have a primary key declaration. However, it is highly recommend for both referential integrity and performance improvements. An entity may have an unlimited number of primary key fields defined. Some databases have restrictions on the length of the primary key. | ||
---|---|---|
Attribute name |
Required? |
Usage |
|
Yes |
This is the name of the field. |
If performance is an issue, you may optionally configure one or more index elements for an entity. Indexes are configured as shown here:
index element tag (Not required) | ||
---|---|---|
Attribute name |
Required? |
Usage |
|
Yes |
Name to use when using this index. Note: there is a limit of 18 characters or less for this value. |
|
No |
Valid values: Default: |
index-field element tag | ||
|
Yes |
The name of the entity field to use as the index. |
To configure the following entity behavior for an individual entity, use the settings as shown here:
Configure an XML declaration similar to the following: |
Behavior |
---|---|
|
By default, OFBiz will create the following entity fields: In cases where you are reading and writing to a non-OFBiz database entity, you may want to turn off this behavior. |
|
Set this entity to never be cached. |
|
Set the range of sequence identifiers used when getting a new sequence identifier using Entity Engine interfaces. The default is "10". |
Field elements
map the target database columns to the equivalent OFBiz field definition. To add one or more column definitions as field entries, use the field
element with the following attribute settings:
field element tag (Required) Field elements configure one or more columns for the entity. | ||
---|---|---|
Attribute name |
Required? |
Usage |
|
Yes |
This is the name of the field. |
|
No |
If the database table column name is different from the equivalent entity field name, set the value here. |
|
Yes |
This value may be any supported field type value as defined in the appropriate |
|
No |
To instruct OFBiz to use its own encryption algorithm to encrypt and decrypt this field's value before storage and upon retrieval, set as Note: setting field encryption in this manner is not the same as using the target database encryption support. Default: |
|
No |
If set to Default: |
|
No |
Sets not-null constraints on the database (instead of the field type). Default: |
Just as physical database tables may be associated with one another through defined "relationships", OFBiz entities may be related. Use the relation
element attribute settings to define one or more relational associations between the defined entity and any other OFBiz entities as described here:
relation element tag (Not required) This element configures one or more relationships for the associated entity. An entity may be related to an unlimited number of other entities using these XML relationship declarations: | ||
---|---|---|
Attribute name |
Required? |
Usage |
|
Yes |
Valid values: Note: OFBiz automatically creates a foreign key for one-to-one entity relationships. If you don't want a foreign key created, use the |
|
Yes |
An "alias" or name to use for this field, when used as a foreign key. Note: this must be 18 characters or less. |
|
Yes |
The name of the entity that is the target in this relationship. All relationships are defined from the defined entity to a target entity as specified using the |
key-map element tag This element is required if the related entity primary key fields do not have the same name as the entity being defined. There may be an unlimited number of | ||
|
Yes |
The field name from the defined entity that represents the primary key used in this relationship. |
|
Yes |
The name of the primary key in the related entity used to configure this relationship. |
13.58.121.8