Integration test for handler with ORM

Hi all,

After seeing the video from Luis about setting up the testing options
of Coldbox, I decided to finally give proper testing a serious look.
Something I always wanted to do, but never took the time to

I have set up my environment according to the video, did the basic
tests to check if the Welcome message was set, and everything works
like expected.

But now I want to test my own handlers, for which I use ORM. I have
enabled ORM in the application.cfc of the test suite, because at first
I got an error saying that ORM was nog enabled.

Now I call event, products.showcategory. It call the productservice
and puts an object in the request collection.
But when I run a test, calling the event en debug the output on the
screen via debug(event.getCollection()), I get the following error:

Result: railo.runtime.exp.NativeException: failed to lazily initialize
a collection, no session or session was closed.

I have checked if session variables were enabled in my Application.cfc
in the test directory, but that is the case.

Are there some extra steps to take when debugging a ORM handler? For
your information, I am using an actual ProductService.cfc, which is
injected by Wirebox into my handler. But that is all handled in the
product handler, so the test handler does not need to know about this,

This is the code in my handler:

var event = "";
//Place any variables on the form or URL scope to test the handler. = "5"
event = execute("product.tooncategorie");

And this is the original handler event:

var rc = event.getCollection();
rc.start = Event.getValue('startrow', '1');
rc.categorie =
rc.qProductsForCategory =

Am I overlooking something here?

Hope you can help,

Kind regards,


Did you follow the steps here?


Hi Curt,

Thanks for your repsonse. I did not see the posting earlier, but I
followed it now.

I added this line to my test folder's application.cfc:
<cfset this.mappings['/baseApp'] = expandpath('../')>

I beleive this is correct, since my test folder is 1 directory under
the root.

Then I added this to the ORM setup:

eventHandling = true,
eventHandler = "/baseApp/model/utilities/ORMEventHandler"

But I am still seeing the same error...

railo.runtime.exp.NativeException: failed to lazily initialize a
collection, no session or session was closed

One thing that is different from your example, is that I am using the
ORM eventhandler here, but I adjusted the path to that CFC as well...

What am I missing?

Kind regards,


That error message indicates that you are trying to access a relationship after the Hibernate session has already closed. Are you by chance storing the object in the ColdFusion session scope?

Hi Matt,

No, that is not the case here... I am not using the session scope at
all, this is just a simple example site. That's the strange thing
about the error...


Nothing in the code you’ve posted is jumping out at me, but the issue is definitely caused by accessing a relationship after the Hibernate session is closed. (NOTE: The CF session and the Hibernate session having nothing whatsoever to do with one another.)

Are you getting this error in a or something like that? Can you show us more of your code?

Ahh… just saw the debug() line from your original post. Yes, that is essentially a . So, I don’t know the specifics of what MXUnit is doing under the hood here, but that line is taking place after the Hibernate session is closed, and therefore throwing the exception you are seeing. This might be a good question for the MXUnit list.

Yeah I ran into a bunch of issues when I first started writing integration tests because I was copying the debug() code examples in the ColdBox docs.

After some discussion with the MxUnit guys they suggested that you shouldn’t really be using debug() unless you have a real purpose for it, as it at very best hits performance, at the very worst throws strange errors or crashes the server through eating all the available memory.


In all reality debug is essential to see the output in the test. Maybe add a top to it so when it dumps it does not do a full search in orm entities.

Ok, when I remove the debug line, which was just there for testing
purposes, the error is gone. It just makes it a bit more difficult to
see which results I am getting back, so that I can write my tests. But
I'll think of a better way to test this!

Thanks for helping me get on my way!

Kind regards,


Yes i tjink The debug method needs a top on it for this purpose

Luis Majano
Ortus Solutions, Corp
Toll free phone/fax: 1-888-557-8057
Mobile: 909-248-3408