For the complete documentation index, see llms.txt. This page is also available as Markdown.

ORM Entity Injection

BoxLang is the preferred language for new ColdBox/WireBox applications, and its ORM approach differs from the legacy CFML/Hibernate pattern below. Pick the tab that matches your engine.

WireBox uses a per-request transient injection cache by default, so repeated autowire() calls for the same entity mapping during a request reuse the resolved injections and delegations. You can disable this globally via transientInjectionCache or per-entity with the transientCache="false" annotation.

BoxLang ORM (bx-orm)

BoxLang's ORM module lets you declare a persistent entity directly as a class, using standalone @persistent/@entityName annotations instead of a .cfc-style cfclocation setting:

@entityName( "Auto" )
@persistent
class {
    property name="id"    type="string" fieldtype="id" ormtype="string";
    property name="make"  type="string";
    property name="model" type="string";
}

There is currently no documented automatic @inject-on-property support for ORM-managed entities (entities are instantiated by Hibernate, not by WireBox), so the safe, documented pattern is to look up WireBox-managed services manually from inside an entity lifecycle hook (onPreInsert(), onPreUpdate(), onPreDelete()) via the application-scoped injector:

@entityName( "Auto" )
@persistent
class {
    property name="id"    type="string" fieldtype="id" ormtype="string";
    property name="make"  type="string";
    property name="model" type="string";

    function onPreInsert(){
        var pricingService = application.wirebox.getInstance( "services.PricingService" );
        pricingService.applyDefaults( this );
    }
}

Custom ORM Event Handler

On CFML/Hibernate, entity injection is done via a custom ORM event handler rather than on the entity itself. Activate event handling in Application.cfc:

Then create the custom event handler with a postLoad() function that leverages WireBox for DI:

Last updated

Was this helpful?