[Coldbox 4.1] Cannot get entity injection to work.

48 views
Skip to first unread message

Byron Raines

unread,
Jun 1, 2015, 5:43:39 PM6/1/15
to col...@googlegroups.com
I'm trying to get entity injection to work in a CB 4.1/CF11 app.  I have the following:

application.cfc:

this.mappings["/models"] = getDirectoryFromPath(getCurrentTemplatePath()) & "models/";
this.mappings["/cborm"] = getDirectoryFromPath(getCurrentTemplatePath()) & "modules/cborm";

// ORM configuration
this.dataSource = "Brotherhood";
this.ormEnabled = true;
this.ormSettings = {
cfclocation = "/models",
dbcreate = "none",
dialect = "MicrosoftSQLServer",
flushatrequestend = false,
autoManageSession = false,
eventHandling = true,
eventhandler = "models.ORMEventHandler"

models/ORMEventHandler:  

component extends="cborm.models.EventHandler"{
}


partcipant.cfc:

component persistent="true" table="tblParticipant" entityname="participant" schema="dbo" output="false"  
{

property name="arrayOfStructsSort" inject="models:UDF:arrayOfStructsSort:{this}" scope="this" persistent="false";

property name="logger" inject="logbox:logger:{this}" persistent="false" scope="this";
.......
}

Both logger and arrayOfStructsSort  are undefined when I dump the entity.  I have successfully used entity injection in my 3.8.  Can't seem to find what I am missing.  Any ideas where to look next?

thanks in advance.

Byron

br...@bradwood.com

unread,
Jun 1, 2015, 6:56:58 PM6/1/15
to col...@googlegroups.com
How are you creating the ORM entity?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/9b1c013e-1d66-4069-8a3c-6edb365cc13e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Byron Raines

unread,
Jun 2, 2015, 9:46:54 AM6/2/15
to col...@googlegroups.com
I'm calling it through my handler:

component{

property name="participantService" inject="models.participantService";

function edit(event,rc,prc){

rc.participant = participantService.get( rc.ID );

event.setView("participants/edit");
}

Byron

br...@bradwood.com

unread,
Jun 2, 2015, 12:39:22 PM6/2/15
to col...@googlegroups.com
FWIW, the "models." part should be optional since models is the default scan location.  Can you show the service?  Does it extend a ColdBox ORM service?
--------- Original Message ---------

Curt Gratz

unread,
Jun 2, 2015, 12:48:31 PM6/2/15
to col...@googlegroups.com
Do you have ORM injection enabled in your config?


orm = {
injection = {
// enable entity injection
enabled = true,
// a list of entity names to include in the injections
include = "",
// a list of entity names to exclude from injection
exclude = ""
}
};

Curt

Byron Raines

unread,
Jun 2, 2015, 1:54:58 PM6/2/15
to col...@googlegroups.com
Here is my participantService:

component extends="ahb.models.baseService" singleton{
/**
* Constructor
*/
public participantService function init(){
// init super class
super.init(entityName="participant");
// Use Query Caching
   setUseQueryCaching( false );
   // Query Cache Region
   setQueryCacheRegion( 'ORMService.defaultCache' );
   // EventHandling
   setEventHandling( true );
   
   return this;
}


baseService.cfc

component  extends="cborm.models.VirtualEntityService" accessors="true" singleton output="false" {

public BaseService function init( entityName ) {
super.init( entityName=arguments.entityName );
return this;
}

Byron Raines

unread,
Jun 2, 2015, 1:55:41 PM6/2/15
to col...@googlegroups.com
Yes.  It is enabled.  Done many a fwreinit and ORMreload.

Byron

br...@bradwood.com

unread,
Jun 2, 2015, 1:58:53 PM6/2/15
to col...@googlegroups.com
Note, entity injection needs to be enabled in two places.  The Application.cfc, and in the Coldbox config struct that the cborm module uses.  I do believe the default is true though if you don't have the ORM struct in your ColdBox config.
 
 
Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
Subject: [coldbox:24279] Re: [Coldbox 4.1] Cannot get entity injection to work.
From: "Byron Raines" <byron....@gmail.com>
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.

Byron Raines

unread,
Jun 2, 2015, 4:29:34 PM6/2/15
to col...@googlegroups.com
Making headway.

If I use: 

eventhandler = "cborm.models.EventHandler"  in this.ormSettings in application.cfc,

it works as expected.

However, I have my own models/ORMEventHandler.cfc where I extend "cborm.models.EventHandler".  When I do that, i do not get the injection.  I use my own eventhandler to do things like update variables for all my tables like so:

public void function preUpdate( any entity, Struct oldData) {

var currentTime = now();
if (structKeyExists(arguments.entity,"setDateModified"))
arguments.entity.setDateModified(currentTime);
if (structKeyExists(arguments.entity,"setModifiedBy") && len(getInstance('sessionStorage@cbstorages').getVar("user").getID()))
arguments.entity.setModifiedBy(getInstance('sessionStorage@cbstorages').getVar("user").getID());
 
}


If there is a better way to accomplish that, I'm happy to take a look.

Byron

br...@bradwood.com

unread,
Jun 2, 2015, 4:33:24 PM6/2/15
to col...@googlegroups.com
Are you calling the super methods in your own ORM event handler?
--------- Original Message ---------

Byron Raines

unread,
Jun 2, 2015, 4:53:12 PM6/2/15
to col...@googlegroups.com
No.  What method(s) do I need to 'super' for the injection to fire?  Or do I need to have an init function that does the super?

br...@bradwood.com

unread,
Jun 2, 2015, 4:57:38 PM6/2/15
to col...@googlegroups.com
Every method you override in the base class will need to call the super method.  Otherwise, you are negating the base class entirely as the base method never gets called.
--------- Original Message ---------

Byron Raines

unread,
Jun 2, 2015, 9:33:17 PM6/2/15
to col...@googlegroups.com
Thanks for the feedback.  I think I missing something.  The cfc you specific in this.ormsettings.eventhandler is supposed to be a global event handler. All the methods in my models.ORMEventHandler.cfc fire correctly without having to super them.   What should I be using to trigger the entity injection?  Something simple is probably escaping me......

Byron

Byron Raines

unread,
Jun 3, 2015, 12:43:20 PM6/3/15
to col...@googlegroups.com
Hooray.  Working.  In an earlier 3.8 app I was not using postLoad() or postNew() methods.  I am on this 4.1 app.  Added super. on those 2 methods and bingo.

Thanks for your help.

Byron
Reply all
Reply to author
Forward
0 new messages