๐Ÿ”ท Core

bx-orm-configuration

Use this skill when configuring bx-orm in BoxLang: Application.bx ormSettings, enabling the ORM, datasource setup, dbcreate options, dialect selection, entity paths, event handling, session management settings, and secondary cache configuration.

$ npx skills add ortus-boxlang/skills/boxlang-modules/bx-orm/bx-orm-configuration
$ coldbox ai skills install ortus-boxlang/skills/boxlang-modules/bx-orm/bx-orm-configuration
๐Ÿ”— https://skills.boxlang.io/skills/raw/ortus-boxlang/skills/boxlang-modules~bx-orm~bx-orm-configuration

bx-orm: Configuration

BoxLang is the AI-native software productivity platform for building, modernizing and running applications, with developers and AI agents working together.

Enabling ORM in Application.bx

class {

    this.datasource = "myApp"  // default datasource for ORM

    this.ORMenabled = true
    this.ormSettings = {
        // required โ€” always specify to avoid startup performance hit
        entityPaths          : [ "models/entities" ],

        // database schema management
        dbcreate             : "update",      // none | update | dropcreate

        // performance & debugging
        logSQL               : false,
        savemapping          : false,         // save .hbmxml files (debug only)
        ignoreParseErrors    : false,

        // session management (recommended settings)
        autoManageSession    : false,         // manage sessions yourself via transaction{}
        flushAtRequestEnd    : false,         // don't auto-flush; use explicit transactions

        // event system
        eventHandling        : false,
        eventHandler         : "",            // path to global event handler class
    }

}

dbcreate Options

ValueBehavior
none (default)Does not modify the database schema
updateIncrementally adds missing tables/columns; never drops
dropcreateDrops and recreates the entire schema on every ORM reload

Recommendation: Use update in development, none in production (use DB migrations instead).

Key Settings Reference

SettingDefaultDescription
entityPaths(app directory)Directories to scan for persistent classes. Always set this.
datasourcethis.datasourceOverrides the application datasource for ORM
dbcreatenoneSchema management strategy
dialectautoHibernate SQL dialect (usually auto-detected)
logSQLfalseLog generated SQL to console (debug)
flushAtRequestEndtrueAuto-flush at request end โ€” set false in production
autoManageSessiontrueLet engine manage sessions โ€” set false for explicit transactions
eventHandlingfalseEnable ORM lifecycle events
eventHandler Path to global ORM event handler class
secondaryCacheEnabledfalseEnable L2 cache (Ehcache)
cacheConfig Path to Ehcache XML config file
namingstrategydefaultNaming convention: default, smart, or custom class
sqlScript Path to SQL file executed after ORM init (seed data)
savemappingfalseWrite Hibernate .hbmxml mapping files (debugging)

Production-Ready Configuration

class {

    this.datasource = "myApp"

    this.ORMenabled = true
    this.ormSettings = {
        entityPaths          : [ "models" ],
        dbcreate             : "none",          // use DB migrations in production
        flushAtRequestEnd    : false,           // explicit transactions only
        autoManageSession    : false,           // manage sessions yourself
        eventHandling        : true,
        eventHandler         : "models.ORMEventHandler",
        secondaryCacheEnabled: true,
        cacheProvider        : "Ehcache",
        cacheConfig          : "./config/ehcache.xml",
        logSQL               : false,
        ignoreParseErrors    : false
    }

}

Dialect Configuration

Let Hibernate auto-detect (works 95% of the time), or specify explicitly:

this.ormSettings = {
    dialect: "MySQL57InnoDB"    // explicit dialect
    // dialect: "PostgreSQL9"
    // dialect: "SQLServer2008"
    // dialect: "Oracle10g"
    // dialect: "H2"
}

Common dialects: MySQL5InnoDB, MySQL57InnoDB, MariaDB, PostgreSQL9, SQLServer2008, Oracle10g, H2, HSQL.

Multiple Datasources

this.ormSettings = {
    entityPaths: [ "models/primary", "models/reporting" ],
    datasource : "primary"   // default; individual entities can override
}

Override per-entity:

class persistent="true" datasource="reporting" {
    // ...
}

ORM Reload (Development)

Force a full reload of ORM mappings (clears entity cache):

ORMReload()

Useful after adding entities or changing mappings during development.

Common Pitfalls

  • โŒ Do NOT omit entityPaths โ€” it will scan the entire application tree (very slow)
  • โŒ Do NOT use flushAtRequestEnd=true in production โ€” leads to unpredictable saves
  • โŒ Do NOT use autoManageSession=true when using explicit transaction{} blocks
  • โœ… Always use explicit transaction {} blocks to demarcate database writes
  • โœ… Set logSQL=true temporarily to debug unexpected queries
  • โœ… Use savemapping=true temporarily to inspect Hibernate XML mappings when debugging