BxORM
Search the docs Star
Hibernate 7.4, made dynamic

Your tables,
as BoxLang classes.

BxORM is a whole framework on top of Hibernate, built for a dynamic language. Write a class, get a table. Then save, load and query rows as objects with static helpers, fluent criteria, automatic type conversion and errors written for humans. No XML, no Java classes, no casting.

$bx-module install bx-orm
  • 47 BIFs
  • Hibernate 7.4.8.Final
  • ~2x faster boots on large models
  • Open source
Static helpers on every entity
// models/User.bx: one class, one table. That's the mapping.
@persistent
@table( "users" )
@softDelete
class {

    @fieldtype( "id" )
    @generator( "native" )
    property id;

    @ormtype( "string" )
    @unique
    property email;

    @ormtype( "timestamp" )
    @autoTimestamp( "create" )
    property createdDate;

    @fieldtype( "one-to-many" )
    @cfc( "Order" )
    @fkcolumn( "userID" )
    property orders;

    function postCommit( entity, action ){
        // only after a real commit: send the welcome email
    }
}
Getters, setters and static methods are generated at startup
Did you mean [firstName]?
EntitiesRelationshipsStatic helpersCriteriaCase-insensitive HQLNo castingTransactionsEntity eventsBoxCache second-level cacheSoft deleteTimestampsLockingentityToStruct()Human errorsBoot cacheObservabilityEntitiesRelationshipsStatic helpersCriteriaCase-insensitive HQLNo castingTransactionsEntity eventsBoxCache second-level cacheSoft deleteTimestampsLockingentityToStruct()Human errorsBoot cacheObservability
Not a thin wrapper

A whole framework between you and Hibernate.

Hibernate was built for static Java classes, XML mappings and typed parameters. BxORM does all the translation, so a dynamic language gets the whole engine and none of the ceremony.

You write

models/User.bx
User::get( id )
entityCriteria( "User" )
ormExecuteQuery()
transaction{}
catch( "orm.*" )
Plain BoxLang. Nothing else.

BxORM does

Mapping generationClasses become Hibernate mappings, in memory
Generated entity classesA Java facade per entity: every id generator, inheritance
Type conversionBoxLang values to JDBC types and back
Case-insensitive HQLfirstname finds firstName
Static helpersUser::get() on every entity
Criteria builderFluent, checked, always parameterized
Entity eventspreInsert, postCommit, veto
Human errorsorm.* types with the fix
TransactionsOn BoxLang's transaction{}
Second-level cacheEvery region is a BoxCache
Boot cacheSkip parsing in production
ObservabilityonORMQuery, onORMFlush events

Engine

Hibernate ORM
7.4.8.Final: the query engine, dialects and sessions

Database

Any JDBC database
MySQLMariaDBPostgreSQLSQLiteH2CockroachDBSQL ServerOracleDerby

Hibernate on its own

  • Java classes or XML for every entity
  • Values must already be the right Java type
  • Case-sensitive HQL names
  • Stack traces in Hibernate's terms
  • Its own transactions and its own cache

Hibernate through BxORM

  • A BoxLang class; mappings are generated in memory
  • "42", dates and booleans converted for you
  • Write HQL in any case, like the rest of BoxLang
  • orm.* errors with your names and the fix
  • BoxLang's transaction{} and BoxCache
Static helpers

Every entity is its own repository.

No service objects, no base class, no injection. At startup every entity class gets static methods, and each one is the BIF you already know with the entity name filled in: same session, same events, same errors.

Load
get()getOrFail()getAll()read()getReference()
Find
findWhere()findAllWhere()first()exists()count()list()
Create and update
new()firstOrNew()firstOrCreate()updateWhere()
Delete
deleteWhere()criteria().deleteAll()entityDelete( entity )
deleteWhere() runs one DELETE and refuses an empty filter. entityDelete() fires events and honors soft delete.
Query
criteria()executeQuery()
handlers/Orders.bx
function show( event, rc, prc ){
    // orm.notFound with a clear message if it's not there
    prc.order = Order::getOrFail( rc.id );
}

function index( event, rc, prc ){
    prc.orders = Order::list( {
        max    : 25,
        offset : ( rc.page - 1 ) * 25,
        sort   : "createdDate desc"
    } );
    prc.total = Order::count( { status : "open" } );
}

function tag( event, rc, prc ){
    // find it, or create it on first use
    return Tag::firstOrCreate( { name : rc.tag } );
}
Criteria queries

Queries that read like sentences.

entityCriteria() builds a query one method at a time. Property names are checked as you go, values are always bound as parameters, and a dotted path joins its associations for you.

  • Automatic joins from paths like manufacturer.name
  • anyOf(), allOf(), subqueries, projections and grouping
  • paginate(), streaming, and bulk updateAll() / deleteAll()
  • asStruct() builds JSON-ready structs without loading entities
  • cborm's method names, so cborm code reads the same
inventory.bxs
cars = entityCriteria( "Vehicle" )
    .isEq( "manufacturer.name", "Ford Motor Company" )
    .isGt( "year", 2020 )
    .order( "price" )
    .list();
Vehicle yearpricemanufacturer ● Manufacturer name ●country inner join, by BxORM
Same path joined once and reusedLeft joins inside anyOf() and for ordering
No casting

BoxLang types in. BoxLang types out.

BoxLang is dynamic; JDBC is not. BxORM puts a converter on every property, chosen from its ormtype, and uses BoxLang's own casters both ways. The string from your form is stored as an integer, and a date comes back as a BoxLang date.

  • isEq( "id", "42" ) works for a numeric id
  • A value that can't fit its column is an orm.property.type error, not a database surprise
  • HQL names resolve case-insensitively, then the corrected query is cached
Your valueConverterColumnYou get back
rc.id = "42"→IntegerConverter→INTEGER→42
price = "19.99"→BigDecimalConverter→DECIMAL→19.99
created = now()→DateTimeConverter→TIMESTAMP→DateTime
active = true→BooleanConverter→BOOLEAN→true
"from user where firstname = ?"→User.firstName
Hibernate 6 and later resolve HQL names case-sensitively. BoxLang doesn't, so BxORM resolves them for you.
Errors for humans

Errors that tell you what to do next.

Every error BxORM raises is written for BoxLang developers: the message uses your entity and property names, the detail says how to fix it, and misspelled names get a suggestion. All the context is in extendedInfo.

  • Typed orm.* errors: catch one, a family, or all of them
  • The HQL, parameters, generated SQL and constraint name, when you need them
  • ormDiagnostics() never throws and shows the ORM's state
orm.property.unknown
messageManufacturer has no property [nmae].
Did you mean [name]?
detailProperties: id, name, address, vehicles
extendedInfo{ hql : "from Manufacturer where nmae = 'x'", ... }
catch( "orm.constraint.unique" e ){ ... }
orm
├─ orm.entity.notFoundDid you mean [User]?
├─ orm.property.unknown
├─ orm.query.*syntax, semantic, parameter, nonUnique
├─ orm.constraint.*unique, notNull, foreignKey, check
├─ orm.lazy.noSession
└─ orm.staleoptimistic locking
Observability

See every ORM query with BxLens.

BxORM announces each SQL statement, flush and failure as an event. Install BxLens and turn on its ORM integration: your ORM SQL shows up next to your other queries, with the time, the rows and the BoxLang line that ran it.

  • ORM SQL in the Queries panel, the Timeline and the console, labelled ORM
  • The same slow-query and N+1 detection as any other query
  • Flushes, failures and Hibernate statistics per datasource on the ORM pageBoxLang+
  • Off until you turn it on, and no cost when nothing is listening
$ bx-module install bx-lens "collectors" : { "orm" : { "enabled" : true } } Then open the bar on any page, or the console at /~bxlens/index.bxm. ORM in BxLens →
The BxLens ORM page: statements, flushes and failures per datasource, and Hibernate statistics
Screens from bxlens.boxlang.io. ORM statements appear in the Queries panel the same way, labelled ORM.
Boot cache

Start production without parsing a single entity.

BxORM saves everything it works out at startup in a .bxorm/ folder: entity metadata, Hibernate mappings and the generated entity classes. Build it in CI, trust it in production. One setting: ormManifest.

"off" every boot
DiscoverParse entitiesGenerate mappingsGenerate classesSessionFactory
"auto" development
Boot normallyWrite .bxorm/Reload when an entity changes
"trust" production
DiscoverParseGenerateLoad .bxorm/SessionFactory
boxlang module:orm generate→ .bxorm/→ Docker image→ "trust"

The CLI builds the cache with no server, database or application start. A trust boot refuses to start on a stale cache and names what changed.

Median boot time, in seconds

Lower is better
250 entities
off
13.48
auto
14.14
trust
7.12
25 entities
off
5.23
auto
5.10
trust
3.86

Synthetic models with associations, local MariaDB. From the Performance docs. On a cold class cache a trust boot adds about 2 ms per entity.

AI skills

Your coding agent already knows BxORM.

Seven agent skills teach Claude Code, Copilot, Cursor, Codex and friends how BxORM 2 really works: annotations, relationships, criteria, transactions, the boot cache and observability. Install them once and ask in plain words.

bx-orm-entities

Annotations, tables, soft delete, ids and generators, inheritance and static entity methods.

bx-orm-relationships

One-to-one to many-to-many, inverse, lazy loading, cascades and the generated add/has/remove methods.

bx-orm-querying

The entityLoad family, HQL with ormExecuteQuery(), paging, streaming and the query cache.

bx-orm-criteria

entityCriteria(): conditions, joins, subqueries, projections, asStruct() and bulk updates.

bx-orm-transactions

transaction{}, mixing ORM and queryExecute(), savepoints, flushing and the session.

bx-orm-configuration

ormSettings, dialects, naming strategies, caching, the boot cache and the module:orm CLI.

bx-orm-observability

onORMQuery and friends, slow SQL, statistics and ormDiagnostics().

+ every BoxLang skill

Language, modules and frameworks, in one plugin.

# all seven BxORM skills
npx skills add ortus-boxlang/skills/boxlang-modules/bx-orm

# or just one
npx skills add ortus-boxlang/skills/boxlang-modules/bx-orm/bx-orm-criteria
Then just ask
  • "Add an Invoice entity with soft delete and a many-to-one to Customer."bx-orm-entities, bx-orm-relationships
  • "Page the open orders by customer name, 25 at a time, as JSON."bx-orm-criteria
  • "Build the boot cache in our Dockerfile and trust it in production."bx-orm-configuration
  • "Why is this page running 40 queries?"bx-orm-observability

Browse them all at skills.boxlang.io · source in ortus-boxlang/skills

Five minutes

From empty app to your first entity.

The Quick Start, in four steps.

terminal
# CommandBox
box install bx-orm bx-mysql

# or the BoxLang module installer
bx-module install bx-orm bx-mysql
Free course

Learn BxORM, one lesson at a time.

Seventeen short lessons: twelve from your first entity to a production boot, then five to go further with inheritance, testing, cborm, AI and moving from CFML. Every lesson ends with code you can run, and your progress is saved in your browser.

17 lessonsAbout 3 hoursMark lessons complete
Start lesson 1

The essentials

Going further

And the rest

Everything else you'd expect. And some you wouldn't.

Soft delete

@softDelete: deletes mark the row, and every load skips it.

Automatic timestamps

@autoTimestamp( "create" ) and "update", set for you.

Structs and queries

entityToStruct() for JSON APIs, mementifier compatible. entityToQuery() for reports.

Events with a veto

Return false from preInsert to cancel. postCommit only fires for real commits.

Cache on BoxCache

The second-level cache runs on BoxLang caches, distributed ones included.

Observability

onORMQuery, onORMFlush and onORMException, free when nobody listens.

Locking and read-only

Pessimistic locks, optimistic versions and read-only loads.

Rich models

Composite keys, single-table and joined inheritance, value collections.

Databases

Every database Hibernate supports.

MySQLMariaDBPostgreSQLSQLiteH2CockroachDBSQL ServerOracleDerbyDB2
Moving over

Bring the ORM code you already have.

Ecosystem

Part of the BoxLang family.

Your first entity is five minutes away.

Install the module, point it at a datasource and save your first row as an object.

$bx-module install bx-orm