Overview
A quick overview of cborm
The
cborm
module will enhance your ORM Entities and ColdBox application by providing you with features in the following areas:- Active Record Pattern
- You can extend your entities from our
ActiveEntity
class and take advantage of both Active Record and Hibernate ORM
- Automatic CRUD Resource Handler
- If you extend our
cborm.models.resources.BaseHandler
it will generate the full CRUD for a specific entity based on ColdBox Resources.
- Entity Population
- Easily populate entities from JSON, structs, XML, and queries and build up even the entity relationships from flat data.
- Easily extract the data from entities and their relationships so you can marshall them to JSON, XML, etc.
- Hibernate Criteria/JPA Queries
- Tap into the real power of Hibernate. cborm will allow you to execute native criteria/jpa queries. Even return arrays of structs, or arrays of mixed objects, native SQL, and much more.
- ORM Events
- Easily listen to multiple ORM events via ColdBox Interceptors
- Service Layers
- Enhance the ability to list, query, find entities, work with native hibernate constructs, and more. You don't even have to create the service objects, we can create virtual ones for you.
- Validation
- We provide you with a
unique
validator to validate against unique columns and much more.
Just write your entities and their relationships and we will take care of the rest!

Let's begin our adventure with the
BaseORMService
model. This model can be injected or requested via WireBox and will be used to interact with any entity in our system or with Hibernate directly:// inject via DSL
property name="ormService" inject="entityService";
// inject via alias
property name="ormService" inject="[email protected]";
// use via alias
getInstance( "[email protected]" );
// use via dsl
getInstance( dsl="entityService" );
This service object acts as an abstraction layer to the ColdFusion ORM (Hibernate) and can work with any entity in your system as all methods most likely receive the
entityName
argument. You will be able to do the following category of actions from this service class:- Hibernate Session utility methods
- Entity metadata methods
- Querying methods
- Criteria Queries or fluent SQL
- Getters
- Finders
- Dynamic Finders
- Counters
- Dynamic Counters
- Persistence (save, update, delete) and bulk persistence with transactions
- Eviction Methods
- Population Methods
This means that you don't need to create a service layer CFC in order to work with ORM entities, you can leverage this abstraction to work with your ORM needs. You can also specifically bind (root) the service to a specific entity, which we lovingly call a
VirtualEntityService
. This way you don't have to be passing the entity names left and right, the virtual entity service will be constructed with the name and all operations will be done upon that entity.Once you have access to the injected base ORM service, you can use it in all of its glory.
Important Please check out the latest API Docs for the latest methods and functionality: https://apidocs.ortussolutions.com/#/coldbox-modules/cborm/
component{
inject name="ormService" inject="entityService";
function saveUser( event, rc, prc ){
// retrieve and populate a new user object
var user = populate( ormService.new( "User" ) );
// save the entity using hibernate transactions
ormService.save( user );
relocate( "user.list" );
}
function list( event, rc, prc ){
// get a listing of all users with pagination and filtering
prc.users = ormService.list(
entityName = "User",
criteria = { isActive : true },
sortOrder = "fname",
offset = event.getValue( "startrow", 1 ),
max = 20
);
event.setView( "user/list" );
}
// Dynamic Finders
function findUsers( event, rc, prc ){
prc.data = ormService.findByRoleAndIsActive( "User", "Admin", true );
}
// Fluent Criteria Queries
function searchContent( event, rc, prc ){
prc.dataStream = ormService
.newCriteria( "Content" )
.isEq( "published", rc.isPublished )
.isLt( "publishedDate", now() )
.or(
ormService.getRestrictions().isNull( "expireDate" ),
ormService.getRestrictions().isGT( "expireDate", now() )
)
.isEq( "passwordProtection", "" )
.joinTo( "activeContent", "ac" )
.like( "title", "%#rc.searchTerm#%" )
.asStream()
.list( offset=rc.offset, max=50 );
event.setView( "content/search")
}