The complete list of context object properties and tool functions available in template bodies. These variables are injected into the Velocity context at generation time.
Context at a Glance
Top-level variables a template can access during generation.
| Variable | Description |
|---|
$entity | The current table's entity — name, field list, soft-delete settings, plus the entity variables the pack declared |
$field | One field of the entity — iterate with #foreach($field in $entity.fields) |
$env | Project-wide variables — values entered in Templates Variables in Project Configuration |
$table | The source table — table name, schema, PK column list, and more |
$projectConfig | The full project configuration — includes the Audit Table settings (auditConfig) |
$databaseInfo | Target DBMS info — product name and version (prefer $codegen.isOracle() etc. over reading directly) |
$paid | Whether the current account is on a paid plan (boolean) |
$codegen · $types … | Tools — see the $codegen · $types · $java · $ts · $py functions below. The standard Velocity DateTool ($date) is also available. |
Pack variable flattening
Entity and field variables declared in the language profile are flattened onto the $entity / $field roots right before rendering. If you declared an entity variable subPackage, templates read it as $entity.subPackage. When a built-in property has the same name, the pack variable wins.
$entity — Entity
The entity of the table being generated. Name-case variants are precomputed as properties.
| Property | Description |
|---|
name | Entity name (NAME in the table's Code Generator tab, usually PascalCase) |
comment | Table comment |
alias | Alias (Alias in the Code Generator tab) |
var | lowerCamel of name — e.g. myName (for variable names) |
snakeLower | snake_case of name — e.g. my_name |
snakeUpper | Uppercase SNAKE_CASE of name — e.g. MY_NAME |
kebabLower | kebab-case of name — e.g. my-name |
kebabUpper | Uppercase KEBAB-CASE of name — e.g. MY-NAME |
fields | Field array — the #foreach target |
fieldMap | Map of DB column name → field — for looking up a field by column name |
softDelete | Soft-delete settings object (table below) |
(entityVariables key) | (Pack entity variables) — keys declared as entityVariables in the language profile appear on the root — e.g. $entity.subPackage |
$entity.softDelete properties
If disabled or no flag column is set, only enabled=false is guaranteed. Properties marked * are derived at generation time from the column types.
| Property | Description |
|---|
enabled | Whether soft delete is enabled |
flagColumn | Delete-flag column (DB column name) |
deletedValue | When the flag is not boolean — the value meaning deleted (e.g. Y, 1) |
activeValue | When the flag is not boolean — the value meaning active (e.g. N, 0) |
dateColumn | Deleted-at column (DB column name, optional) |
dateFormat | Date format to store when the date column is a string |
flagBoolean | * Whether the flag column is a boolean type |
flagString | * Whether the flag column is a string type (for SQL literal quoting) |
flagField | * Field name of the flag column |
dateString | * Whether the date column is a string type |
dateField | * Field name of the date column |
$field — Field (Column)
An element of $entity.fields. Carries the field name, the resolved type mapping, and the original DB column.
| Property | Description |
|---|
name | Field name — the DB column name with Column Renamer rules applied |
comment | Field comment |
mappedType | Resolved type object (table below) — reflects the active pack's type mappings and user overrides |
defaultValue | Field-level default value |
deletedMark | Whether this field is the soft-delete flag |
metaAttributes | META attribute array — each item has name · value. Prefer $codegen.getMetaAttribute() for lookups |
column | The original DB column (table below) |
(fieldVariables key) | (Pack field variables) — keys declared as fieldVariables in the language profile appear on the root — e.g. $field.customType |
$field.mappedType properties
| Property | Description |
|---|
mappedType.type | Intermediate type identifier — M_LONG, M_STRING, ... (see "Intermediate Types" below) |
mappedType.target | Target language type — e.g. java.lang.Long, number. Prefer $types.typeOf($field) for output |
mappedType.category | Type category — number · text · datetime · boolean · array · object · url |
$field.column main properties
The original column information read from the database.
| Property | Description |
|---|
column.name | DB column name |
column.remarks | Column comment |
column.type | DB type — e.g. VARCHAR, BIGINT |
column.size | Length/size |
column.decimalDigits | Decimal digits |
column.nullable | Whether NULL is allowed |
column.autoIncrement | Whether auto-increment |
column.defaultValue | DB default value |
$env & Other Objects
$env — Project-wide variables
Values users entered for the global variables declared in the language profile. Dots in keys become nested objects — declare package.core and read $env.package.core.
$table — Source table
| Property | Description |
|---|
name | Table name |
schemaName | Schema name |
primaryKeys | Array of PK column names (DB column names) |
columns | Column array (raw) |
$projectConfig — Project configuration
The whole project configuration is exposed. The part relevant to generation is auditConfig — prefer the $codegen audit functions over reading it directly.
| Property | Description |
|---|
auditConfig.auditTable | The audit reference table |
auditConfig.aae | Audit Entity Interface class name |
auditConfig.aaie | Immutable Audit Entity Interface class name |
auditConfig.creationAuthorList, … | Four candidate column-name lists for create/update tracking — creationAuthorList · creationDateList · lastModificationAuthorList · lastModificationDateList |
$databaseInfo — Target DBMS
| Property | Description |
|---|
databaseProductName | JDBC product name — e.g. MariaDB. Prefer $codegen.isMariaDB() etc. for branching |
databaseProductVersion | Product version (empty if never connected) |
$paid — Paid plan flag
A boolean indicating whether the current account is on a paid plan. Templates may branch their output on it.
$codegen Functions
Language-neutral generation helpers: naming conversion, DBMS branching, PK/field selection, audit checks, and more.
Naming · Strings
| Function | Description |
|---|
$codegen.toLowerCamel(value) | UpperCamel → lowerCamel. e.g. MyName → myName |
$codegen.toUpperCamel(value) | lowerCamel → UpperCamel. e.g. myProp → MyProp |
$codegen.toUpperUnderscore(value) | UpperCamel → UPPER_UNDERSCORE. e.g. MyName → MY_NAME |
$codegen.toPath(part1, part2, …) | Replaces dots with slashes in each argument, then joins them as a path. e.g. com.foo and bar → com/foo/bar |
$codegen.join(sep, v1, v2, …) | Joins values with the separator, skipping blanks and collapsing repeated separators |
$codegen.replace(text, search, repl) | Character replacement — replaces searchString chars in text with replacement |
$codegen.printIf(cond, value) | Prints value only when cond is true (otherwise an empty string) |
$codegen.printVelocityVar(value) | Wraps value as a dollar-brace reference string — for leaving literal Velocity notation in the output |
$codegen.printIgnoreFirst(count, value) | Empty string when count is 1, otherwise value — for skipping the separator before the first loop item |
DBMS Checks · SQL Helpers
| Function | Description |
|---|
$codegen.isOracle() | Whether the target DBMS is Oracle |
$codegen.isMySQL() | Whether the target DBMS is MySQL |
$codegen.isMariaDB() | Whether the target DBMS is MariaDB |
$codegen.isPostgreSql() | Whether the target DBMS is PostgreSQL |
$codegen.isMsSql() | Whether the target DBMS is SQL Server |
$codegen.getColumnName(columnName) | Bracket-quoted column name on SQL Server, as-is elsewhere |
$codegen.getSchemaPrefix() | schema. prefix string when the connection's schema-prefix setting is on, otherwise empty |
$codegen.useSchemaPrefix() | Whether the connection's schema-prefix setting is on |
PK · Field Selection
| Function | Description |
|---|
$codegen.getPkAttr() | List of PK fields (in $table.primaryKeys order) |
$codegen.getNonPkAttr() | List of non-PK fields |
$codegen.isSinglePk() | Whether the PK is a single column |
$codegen.isSinglePkAndLongTypeAndNameIsId() | Whether there is exactly one PK named id with intermediate type M_LONG — the standard id pattern |
$codegen.isPk($field.column) | Whether the given column ($field.column) is a PK |
$codegen.getDeletedField() | The field with deletedMark=true (null if none) |
$codegen.hasDeletedField() | Whether a deletedMark field exists |
$codegen.getMetaAttribute(name, $field) | The value of the META attribute matching name on the field (empty string if missing) |
Sequences · Key SQL
| Function | Description |
|---|
$codegen.hasSequence() | Whether $entity.sequenceName is non-empty (when declared as a pack entity variable) |
$codegen.getSelectKeyStatement() | Per-DBMS PK retrieval SQL — sequence-based on Oracle/PostgreSQL, auto-increment-based on MySQL/MariaDB/SQL Server (for MyBatis selectKey) |
$codegen.getSelectKeyOrder() | When selectKey runs — before on Oracle/PostgreSQL, after elsewhere |
Audit (create/update tracking columns)
| Function | Description |
|---|
$codegen.hasAuditTable() | Whether an Audit Table is configured for the project |
$codegen.hasCreated() | Whether both creation author and date columns exist |
$codegen.hasModified() | Whether both modification author and date columns exist |
$codegen.isCreationAuthor(name) | Whether the field name is in the creation-author candidate list |
$codegen.isCreationDate(name) | Whether the field name is in the creation-date candidate list |
$codegen.isModificationAuthor(name) | Whether the field name is in the modification-author candidate list |
$codegen.isModificationDate(name) | Whether the field name is in the modification-date candidate list |
$codegen.isCreationField(name) | Whether it is a creation author or date column |
$codegen.isModificationField(name) | Whether it is a modification author or date column |
$codegen.isAuditField(name) | Whether it is any create/update tracking column |
$codegen.isAuditDateField(name) | Whether it is a creation-date or modification-date column |
Validation Keywords
| Function | Description |
|---|
$codegen.validationsEntity($entity) | Validation keywords across all entity fields (deduplicated) |
$codegen.validationsField($field) | Validation keywords for a field — notblank for NOT NULL strings, notnull otherwise, utf8size for sized strings. PK and audit fields are skipped |