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.

AttributeTypeDefaultMeaning
nameStringrequiredEntity name.
packageNameStringrequiredEntity package, for grouping in entitymodel.xml output.
tableNameString""Table name. Defaults to the entity name in upper case with underscores.
descriptionString""Entity description.
titleString""Human-readable title.
authorString""Author note.
copyrightString""Copyright note.
versionString""Version note.
defaultResourceNameString""Default UI-label resource for field titles.
dependentOnString""Entity this one depends on for load order.
sequenceBankSizeint0Sequence bank size for id generation.
enableLockbooleanfalseWhether to enable optimistic locking.
noAutoStampbooleanfalseWhether to skip automatic createdStamp/lastUpdatedStamp fields.
neverCachebooleanfalseWhether to disable entity caching.
neverCheckbooleanfalseWhether to skip schema checks.
autoClearCachebooleantrueWhether to clear cache automatically on change.
redefinitionbooleanfalseWhether this redefines an existing entity, to suppress duplicate warnings.
fieldsField[]{}Field list.
primaryKeysPrimaryKey[]{}Primary key field list.
relationsRelation[]{}Relations to other entities.
indexesIndex[]{}Index list.

@Field#

One field, inside @Entity(fields = {...}).

AttributeTypeDefaultMeaning
nameStringrequiredField name.
typeStringrequiredField type, for example id, id-ne, name, date-time, numeric.
colNameString""Column name. Defaults to the field name in upper case with underscores.
descriptionString""Field description.
encryptString"false""false", "true", or "salt".
enableAuditLogbooleanfalseWhether to write field changes to the audit log.
notNullbooleanfalseWhether the column is NOT NULL.
fieldSetString""Named field set this field belongs to.
selectString""Whether to include the field in default SELECT operations. Empty means true.
validatorsValidate[]{}Validation rules.

@PrimaryKey#

One primary key field, inside @Entity(primaryKeys = {...}).

AttributeTypeDefaultMeaning
fieldStringrequiredField name that is part of the primary key.

@Relation#

One relation to another entity, inside @Entity(relations = {...}).

AttributeTypeDefaultMeaning
typeRelationTyperequiredONE, MANY, or a related enum value.
relEntityNameStringrequiredRelated entity name.
keyMapsKeyMap[]requiredField mappings between the two entities.
titleString""Relation title, used to disambiguate multiple relations to the same entity.
descriptionString""Relation description.
fkNameString""Foreign key constraint name.

@KeyMap#

One field mapping, inside @Relation(keyMaps = {...}) or @ViewLink(keyMaps = {...}).

AttributeTypeDefaultMeaning
fieldNameStringrequiredField on this entity.
relFieldNameString""Field on the related entity. Defaults to the same name as fieldName.

@Index#

One index, inside @Entity(indexes = {...}).

AttributeTypeDefaultMeaning
nameStringrequiredIndex name.
fieldsIndexField[]requiredFields in the index.
uniquebooleanfalseWhether the index enforces uniqueness.
descriptionString""Index description.

@IndexField#

One field inside @Index(fields = {...}).

AttributeTypeDefaultMeaning
nameStringrequiredField name.
functionIndexFunctionIndexFunction.NONEFunction applied to the field in the index, if any.

@ViewEntity#

Defines one view entity: a read-only join across member entities.

AttributeTypeDefaultMeaning
nameString""View entity name. Defaults to the class’s simple name with Entity/View stripped.
packageNameStringrequiredPackage the view entity belongs to.
titleString""Human-readable title.
descriptionString""View entity description.
dependentOnString""Entity this view depends on for load order.
defaultResourceNameString""Default UI-label resource for field titles.
neverCachebooleanfalseWhether to disable caching.
autoClearCachebooleantrueWhether to clear cache automatically on change.
redefinitionbooleanfalseWhether this redefines an existing view entity.
aliasColumnsString""Whether to alias columns. Empty uses the entityengine.xml default.
copyrightString""Copyright note.
authorString""Author note.
versionString""Version note.
membersMemberEntity[]{}Member entities the view joins.
memberDependencyOrderString""Explicit member load order.
aliasAllsAliasAll[]{}Alias-all blocks, one per member.
aliasesAlias[]{}Explicit field aliases.
viewLinksViewLink[]{}Join conditions between members.
relationsRelation[]{}Relations from the view to other entities.
conditionEntityCondition@EntityConditionView-level WHERE condition.

@MemberEntity#

One member of a view entity, inside @ViewEntity(members = {...}).

AttributeTypeDefaultMeaning
entityAliasStringrequiredAlias used to refer to this member inside the view.
entityNameStringrequiredEntity name of the member.
descriptionString""Member description.

@Alias / @AliasAll#

@Alias aliases one field inside @ViewEntity(aliases = {...}); @AliasAll aliases every field of one member inside @ViewEntity(aliasAlls = {...}).

AnnotationAttributeTypeDefaultMeaning
@AliasnameStringrequiredAlias field name on the view.
@AliasentityAliasString""Member entity alias the field comes from.
@AliasfieldString""Field name on the source entity. Defaults to name.
@AliascolAliasString""Column alias in the generated SQL.
@AliasprimKeyString""Whether this alias is part of the view’s primary key.
@AliascomplexAliasComplexAlias@ComplexAlias(operator = "")Computed expression instead of a plain field.
@AliasAllentityAliasStringrequiredMember entity alias to alias every field of.
@AliasAllprefixString""Prefix added to each generated alias name.
@AliasAllexcludesString[]{}Fields to exclude from the alias-all.
bothgroupBybooleanfalseWhether to include the field(s) in GROUP BY.
bothfunctionAggregateFunctionAggregateFunction.NONEAggregate function applied.
bothfieldSetString""Named field set the alias(es) belong to.
bothselectString""Whether to include in the default SELECT.
bothdescriptionString""Description.

One join condition between two members, inside @ViewEntity(viewLinks = {...}).

AttributeTypeDefaultMeaning
entityAliasStringrequiredLeft-hand member alias.
relEntityAliasStringrequiredRight-hand member alias.
keyMapsKeyMap[]requiredField mappings that join the two members.
relOptionalbooleanfalseWhether to use a LEFT OUTER JOIN instead of an INNER JOIN.
conditionEntityCondition@EntityConditionExtra join condition.
descriptionString""Description.

@ExtendEntity#

Adds fields, relations or indexes to an entity defined elsewhere, without redefining it.

AttributeTypeDefaultMeaning
nameStringrequiredEntity name to extend.
defaultResourceNameString""Overrides the original entity’s default resource name.
dependentOnString""Extra load-order dependency.
sequenceBankSizeint0Overrides the sequence bank size.
enableLockString""Overrides optimistic locking.
noAutoStampString""Overrides the auto-stamp fields setting.
neverCacheString""Overrides the caching setting.
autoClearCacheString""Overrides the auto-clear-cache setting.
fieldsField[]{}Extra fields to add.
relationsRelation[]{}Extra relations to add.
indexesIndex[]{}Extra indexes to add.

@Validate#

One field validation rule, inside @Field(validators = {...}).

AttributeTypeDefaultMeaning
nameStringrequiredValidation method name.

Example: MrpRun#

applications/manufacturing/src/com/ilscipio/scipio/manufacturing/entity/Entities.java, lines 322-349.

java
/**
 * 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 {}

Ask the people who wrote it.

Support, development and training from the team that builds Scipio ERP.