Entity annotations
The @Entity and @ViewEntity annotations and their companions, with a real example from the manufacturing application.
Source: framework/entity/src/com/ilscipio/scipio/entity/def/.
@Entity#
Defines one entity.
| Attribute | Type | Default | Meaning |
|---|---|---|---|
name | String | required | Entity name. |
packageName | String | required | Entity package, for grouping in entitymodel.xml output. |
tableName | String | "" | Table name. Defaults to the entity name in upper case with underscores. |
description | String | "" | Entity description. |
title | String | "" | Human-readable title. |
author | String | "" | Author note. |
copyright | String | "" | Copyright note. |
version | String | "" | Version note. |
defaultResourceName | String | "" | Default UI-label resource for field titles. |
dependentOn | String | "" | Entity this one depends on for load order. |
sequenceBankSize | int | 0 | Sequence bank size for id generation. |
enableLock | boolean | false | Whether to enable optimistic locking. |
noAutoStamp | boolean | false | Whether to skip automatic createdStamp/lastUpdatedStamp fields. |
neverCache | boolean | false | Whether to disable entity caching. |
neverCheck | boolean | false | Whether to skip schema checks. |
autoClearCache | boolean | true | Whether to clear cache automatically on change. |
redefinition | boolean | false | Whether this redefines an existing entity, to suppress duplicate warnings. |
fields | Field[] | {} | Field list. |
primaryKeys | PrimaryKey[] | {} | Primary key field list. |
relations | Relation[] | {} | Relations to other entities. |
indexes | Index[] | {} | Index list. |
@Field#
One field, inside @Entity(fields = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
name | String | required | Field name. |
type | String | required | Field type, for example id, id-ne, name, date-time, numeric. |
colName | String | "" | Column name. Defaults to the field name in upper case with underscores. |
description | String | "" | Field description. |
encrypt | String | "false" | "false", "true", or "salt". |
enableAuditLog | boolean | false | Whether to write field changes to the audit log. |
notNull | boolean | false | Whether the column is NOT NULL. |
fieldSet | String | "" | Named field set this field belongs to. |
select | String | "" | Whether to include the field in default SELECT operations. Empty means true. |
validators | Validate[] | {} | Validation rules. |
@PrimaryKey#
One primary key field, inside @Entity(primaryKeys = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
field | String | required | Field name that is part of the primary key. |
@Relation#
One relation to another entity, inside @Entity(relations = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
type | RelationType | required | ONE, MANY, or a related enum value. |
relEntityName | String | required | Related entity name. |
keyMaps | KeyMap[] | required | Field mappings between the two entities. |
title | String | "" | Relation title, used to disambiguate multiple relations to the same entity. |
description | String | "" | Relation description. |
fkName | String | "" | Foreign key constraint name. |
@KeyMap#
One field mapping, inside @Relation(keyMaps = {...}) or @ViewLink(keyMaps = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
fieldName | String | required | Field on this entity. |
relFieldName | String | "" | Field on the related entity. Defaults to the same name as fieldName. |
@Index#
One index, inside @Entity(indexes = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
name | String | required | Index name. |
fields | IndexField[] | required | Fields in the index. |
unique | boolean | false | Whether the index enforces uniqueness. |
description | String | "" | Index description. |
@IndexField#
One field inside @Index(fields = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
name | String | required | Field name. |
function | IndexFunction | IndexFunction.NONE | Function applied to the field in the index, if any. |
@ViewEntity#
Defines one view entity: a read-only join across member entities.
| Attribute | Type | Default | Meaning |
|---|---|---|---|
name | String | "" | View entity name. Defaults to the class’s simple name with Entity/View stripped. |
packageName | String | required | Package the view entity belongs to. |
title | String | "" | Human-readable title. |
description | String | "" | View entity description. |
dependentOn | String | "" | Entity this view depends on for load order. |
defaultResourceName | String | "" | Default UI-label resource for field titles. |
neverCache | boolean | false | Whether to disable caching. |
autoClearCache | boolean | true | Whether to clear cache automatically on change. |
redefinition | boolean | false | Whether this redefines an existing view entity. |
aliasColumns | String | "" | Whether to alias columns. Empty uses the entityengine.xml default. |
copyright | String | "" | Copyright note. |
author | String | "" | Author note. |
version | String | "" | Version note. |
members | MemberEntity[] | {} | Member entities the view joins. |
memberDependencyOrder | String | "" | Explicit member load order. |
aliasAlls | AliasAll[] | {} | Alias-all blocks, one per member. |
aliases | Alias[] | {} | Explicit field aliases. |
viewLinks | ViewLink[] | {} | Join conditions between members. |
relations | Relation[] | {} | Relations from the view to other entities. |
condition | EntityCondition | @EntityCondition | View-level WHERE condition. |
@MemberEntity#
One member of a view entity, inside @ViewEntity(members = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
entityAlias | String | required | Alias used to refer to this member inside the view. |
entityName | String | required | Entity name of the member. |
description | String | "" | Member description. |
@Alias / @AliasAll#
@Alias aliases one field inside @ViewEntity(aliases = {...}); @AliasAll
aliases every field of one member inside @ViewEntity(aliasAlls = {...}).
| Annotation | Attribute | Type | Default | Meaning |
|---|---|---|---|---|
@Alias | name | String | required | Alias field name on the view. |
@Alias | entityAlias | String | "" | Member entity alias the field comes from. |
@Alias | field | String | "" | Field name on the source entity. Defaults to name. |
@Alias | colAlias | String | "" | Column alias in the generated SQL. |
@Alias | primKey | String | "" | Whether this alias is part of the view’s primary key. |
@Alias | complexAlias | ComplexAlias | @ComplexAlias(operator = "") | Computed expression instead of a plain field. |
@AliasAll | entityAlias | String | required | Member entity alias to alias every field of. |
@AliasAll | prefix | String | "" | Prefix added to each generated alias name. |
@AliasAll | excludes | String[] | {} | Fields to exclude from the alias-all. |
| both | groupBy | boolean | false | Whether to include the field(s) in GROUP BY. |
| both | function | AggregateFunction | AggregateFunction.NONE | Aggregate function applied. |
| both | fieldSet | String | "" | Named field set the alias(es) belong to. |
| both | select | String | "" | Whether to include in the default SELECT. |
| both | description | String | "" | Description. |
@ViewLink#
One join condition between two members, inside @ViewEntity(viewLinks = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
entityAlias | String | required | Left-hand member alias. |
relEntityAlias | String | required | Right-hand member alias. |
keyMaps | KeyMap[] | required | Field mappings that join the two members. |
relOptional | boolean | false | Whether to use a LEFT OUTER JOIN instead of an INNER JOIN. |
condition | EntityCondition | @EntityCondition | Extra join condition. |
description | String | "" | Description. |
@ExtendEntity#
Adds fields, relations or indexes to an entity defined elsewhere, without redefining it.
| Attribute | Type | Default | Meaning |
|---|---|---|---|
name | String | required | Entity name to extend. |
defaultResourceName | String | "" | Overrides the original entity’s default resource name. |
dependentOn | String | "" | Extra load-order dependency. |
sequenceBankSize | int | 0 | Overrides the sequence bank size. |
enableLock | String | "" | Overrides optimistic locking. |
noAutoStamp | String | "" | Overrides the auto-stamp fields setting. |
neverCache | String | "" | Overrides the caching setting. |
autoClearCache | String | "" | Overrides the auto-clear-cache setting. |
fields | Field[] | {} | Extra fields to add. |
relations | Relation[] | {} | Extra relations to add. |
indexes | Index[] | {} | Extra indexes to add. |
@Validate#
One field validation rule, inside @Field(validators = {...}).
| Attribute | Type | Default | Meaning |
|---|---|---|---|
name | String | required | Validation method name. |
Example: MrpRun#
applications/manufacturing/src/com/ilscipio/scipio/manufacturing/entity/Entities.java,
lines 322-349.
/**
* SCIPIO: MRP Run header: one row per executeMrp call with status, counts and errors.
*/
@Entity(
name = "MrpRun",
packageName = "org.ofbiz.manufacturing.mrp",
title = "MRP Run",
fields = {
@Field(name = "mrpId", type = "id-ne"),
@Field(name = "mrpName", type = "name"),
@Field(name = "facilityId", type = "id"),
@Field(name = "facilityGroupId", type = "id"),
@Field(name = "statusId", type = "id"),
@Field(name = "startDate", type = "date-time"),
@Field(name = "finishDate", type = "date-time"),
@Field(name = "eventCount", type = "numeric"),
@Field(name = "proposedProductionRuns", type = "numeric"),
@Field(name = "proposedPurchases", type = "numeric"),
@Field(name = "errorCount", type = "numeric"),
@Field(name = "runByUserLoginId", type = "id-vlong"),
@Field(name = "message", type = "very-long")
},
primaryKeys = {
@PrimaryKey(field = "mrpId")
},
relations = {
@Relation(type = RelationType.ONE, relEntityName = "Facility", fkName = "MRPRUN_FAC",
keyMaps = {@KeyMap(fieldName = "facilityId")}),
@Relation(type = RelationType.ONE, relEntityName = "FacilityGroup", fkName = "MRPRUN_FACGRP",
keyMaps = {@KeyMap(fieldName = "facilityGroupId")}),
@Relation(type = RelationType.ONE, relEntityName = "StatusItem", fkName = "MRPRUN_STTS",
keyMaps = {@KeyMap(fieldName = "statusId")}),
@Relation(type = RelationType.MANY, relEntityName = "MrpEvent",
keyMaps = {@KeyMap(fieldName = "mrpId")})
}
)
public interface MrpRunEntity {}