OFBiz view-entities are a convenient way of constructing SQL JOIN
statements. They do not force the creation of database tables or map to database tables as do entity definitions, but rather they allow OFBiz to create runtime views of related tables so that users may easily access joined tables without creating complicated SQL JOIN
statements.
View-entities are defined in entity definition files along with entity definitions. Make sure you have an entity definition file (to use for any view-entities) configured in an existing ofbiz-component.xml
.
The process for creating one or more view-entities is similar to that of creating an entity definition, and can be done by following these steps:
view-entity
elements as shown here. Please note: XML declarations shown below are for demonstration purposes only. Statements have been removed to make reading easier:<view-entity entity-name="EntityName" package-name="org.ofbiz.somePackageName" never-cache="true" title="My New View Entity"> <!-- Entity definition XML declaration(s) go here. Removed for demonstration purposes --> </view-entity>
view-entity
element with a closing tag (</view-entity>
).https://localhost:8443/webtools/control/entityref
).OFBiz view-entities are a convenient way to create SQL JOIN
statements (joining together table column data from two or more tables) using XML declarations instead of SQL statements. The Entity Engine automatically creates the SQL JOIN
statement any time the view-entity is accessed.
View-entities may be created or removed from the OFBiz Entity Engine data model at any time using the mentioned recipe. View-entities are read-only, and attempts to store data using a view-entity will fail.
An OFBiz view-entity has one or more participating "member" entities. As a convenient way to refer to a member entity, you must create an entity level alias for that member using the member-entity
element as shown here:
member-entity element tag Create a shortcut alias for each view-entity participating member. | ||
---|---|---|
Attribute name |
Required? |
Usage |
|
Yes |
Two-letter to four-letter alias or abbreviation used for the remainder of this definition to represent the full entity name as given in the |
|
Yes |
The name of an existing entity. Note: this attribute is case-sensitive. The value in this field must match an existing entity name. |
Each member entity may have one or more field aliases defined for any existing entity field. All fields are referenced using field aliases within the context of the view-entity. To create field-level aliases, use the alias
element tag as shown here:
alias element tag For example, an
Refers to the field | ||
---|---|---|
Attribute name |
Required? |
Usage |
|
Yes |
Use the entity's alias as configured in the |
|
Yes |
The field from the aliased entity to use as part of this definition. |
complex-alias element tag Within the | ||
|
Yes |
Any supported mathematical operator for the field's data type. |
One or more fields to be joined using the operator-supplied operator. Fields are defined using the |
If all fields for an entity should be returned when calling this view-entity, you may use the shortcut alias-all
element as defined here:
alias-all element tag Return all the fields for the specified entity alias. | |
---|---|
Attribute name |
Usage |
|
Use the entity's alias as configured in the |
To create a SQL OUTER JOIN
(that is, a JOIN
on two tables where records from the joined tables may not have matching pairs), use the view-link
element to define the relationship between one entity and another target entity, and set the rel-optional
value to true:
view-link element tag (Optional) | ||
---|---|---|
Attribute name |
Required? |
Usage |
|
Yes |
The alias for the entity participating in this relation. |
|
Yes |
The alias of the related entity. |
|
No |
Valid values: Default: |
key-map element tag The key-map entity defines the table relationship. | ||
|
The name of the field as defined by the entity pointed to by the |
View-entities may be quite complex. For an in depth treatment of this subject, please see The Open For Business Project: Entity Engine Guide at:
13.59.173.242