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.
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 );
}
}This page's manual-lookup pattern reflects what's currently documented for bx-orm. If a future bx-orm release adds first-class WireBox property injection on entities (mirroring @inject on regular classes), this page will be updated to match.
Last updated
Was this helpful?