Velocity Reference

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.

VariableDescription
$entityThe current table's entity — name, field list, soft-delete settings, plus the entity variables the pack declared
$fieldOne field of the entity — iterate with #foreach($field in $entity.fields)
$envProject-wide variables — values entered in Templates Variables in Project Configuration
$tableThe source table — table name, schema, PK column list, and more
$projectConfigThe full project configuration — includes the Audit Table settings (auditConfig)
$databaseInfoTarget DBMS info — product name and version (prefer $codegen.isOracle() etc. over reading directly)
$paidWhether 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.

PropertyDescription
nameEntity name (NAME in the table's Code Generator tab, usually PascalCase)
commentTable comment
aliasAlias (Alias in the Code Generator tab)
varlowerCamel of name — e.g. myName (for variable names)
snakeLowersnake_case of name — e.g. my_name
snakeUpperUppercase SNAKE_CASE of name — e.g. MY_NAME
kebabLowerkebab-case of name — e.g. my-name
kebabUpperUppercase KEBAB-CASE of name — e.g. MY-NAME
fieldsField array — the #foreach target
fieldMapMap of DB column name → field — for looking up a field by column name
softDeleteSoft-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.

PropertyDescription
enabledWhether soft delete is enabled
flagColumnDelete-flag column (DB column name)
deletedValueWhen the flag is not boolean — the value meaning deleted (e.g. Y, 1)
activeValueWhen the flag is not boolean — the value meaning active (e.g. N, 0)
dateColumnDeleted-at column (DB column name, optional)
dateFormatDate 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.

PropertyDescription
nameField name — the DB column name with Column Renamer rules applied
commentField comment
mappedTypeResolved type object (table below) — reflects the active pack's type mappings and user overrides
defaultValueField-level default value
deletedMarkWhether this field is the soft-delete flag
metaAttributesMETA attribute array — each item has name · value. Prefer $codegen.getMetaAttribute() for lookups
columnThe 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

PropertyDescription
mappedType.typeIntermediate type identifier — M_LONG, M_STRING, ... (see "Intermediate Types" below)
mappedType.targetTarget language type — e.g. java.lang.Long, number. Prefer $types.typeOf($field) for output
mappedType.categoryType category — number · text · datetime · boolean · array · object · url

$field.column main properties

The original column information read from the database.

PropertyDescription
column.nameDB column name
column.remarksColumn comment
column.typeDB type — e.g. VARCHAR, BIGINT
column.sizeLength/size
column.decimalDigitsDecimal digits
column.nullableWhether NULL is allowed
column.autoIncrementWhether auto-increment
column.defaultValueDB 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

PropertyDescription
nameTable name
schemaNameSchema name
primaryKeysArray of PK column names (DB column names)
columnsColumn 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.

PropertyDescription
auditConfig.auditTableThe audit reference table
auditConfig.aaeAudit Entity Interface class name
auditConfig.aaieImmutable Audit Entity Interface class name
auditConfig.creationAuthorList, …Four candidate column-name lists for create/update tracking — creationAuthorList · creationDateList · lastModificationAuthorList · lastModificationDateList

$databaseInfo — Target DBMS

PropertyDescription
databaseProductNameJDBC product name — e.g. MariaDB. Prefer $codegen.isMariaDB() etc. for branching
databaseProductVersionProduct 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.

Intermediate Types & Categories

DB column types are first converted to the intermediate types below; the language profile's type mappings then decide intermediate type → target language type. The category drives checks like $types.isDate($field).

CategoryProperty
textM_STRING · M_CHAR · M_CLOB
numberM_INTEGER · M_LONG · M_BIGINTEGER · M_BYTE · M_DOUBLE · M_FLOAT · M_BIGDECIMAL
booleanM_BOOLEAN
datetimeM_LOCALDATE · M_LOCALTIME · M_LOCALDATETIME · M_ZONEDDATETIME · M_SQLDATE · M_UTILDATE · M_INSTANT · M_TIME · M_TIMESTAMP
arrayM_ARRAY · M_BYTES · M_BLOB
urlM_URL
objectM_REF · M_OBJECT

$codegen Functions

Language-neutral generation helpers: naming conversion, DBMS branching, PK/field selection, audit checks, and more.

Naming · Strings

FunctionDescription
$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

FunctionDescription
$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

FunctionDescription
$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

FunctionDescription
$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)

FunctionDescription
$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

FunctionDescription
$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

$types Functions

Language-agnostic type helpers that read the field's resolved type ($field.mappedType).

FunctionDescription
$types.categoryOf($field)The field's type category — datetime · number · boolean · text · array · object · url
$types.isCategory($field, category)Whether the field is of the given category
$types.typeOf($field)Simple name of the target type — e.g. java.lang.Long → Long
$types.importOf($field)Full type name for imports — e.g. java.lang.Long
$types.simpleNameOf(fullType)Full type-name string → simple name
$types.isDate($field)Whether the category is datetime
$types.isNumber($field)Whether the category is number
$types.isBoolean($field)Whether the category is boolean
$types.isText($field)Whether the category is text
$types.isArray($field)Whether the category is array
$types.isDateOnly($field)Whether it is a date without time (M_LOCALDATE)
$types.isLongText($field)Whether it is long text — CLOB/BLOB, or a string sized 1000+

$java · $ts · $py Functions

Per-language convenience helpers. $types and $codegen alone cover the basics; these add language-specific extras.

$java — Java

FunctionDescription
$java.imports()Collects import lines from the entity's field types — excludes java.lang.*, deduplicated and sorted
$java.simpleName(fullType)Full type name → simple name. e.g. java.lang.Long → Long

$ts — TypeScript

FunctionDescription
$ts.propertyType($field)The field's TS type — always Date for the datetime category, otherwise the mapped target, falling back to any
$ts.interfaceName(value)PascalCase normalization — e.g. user_profile → UserProfile

$py — Python

FunctionDescription
$py.snakeCase(value)snake_case conversion (PEP8) — e.g. UserProfile → user_profile
$py.typeHint($field)The field's Python type hint — str · int · float · bool · datetime.datetime, etc.