ormcoldfusionrailoapplication.cfc

ColdFusion - Enabling ORM stops onApplicationStart from running


Can anyone explain this behaviour to me? I have set up a bunch of application scoped settings in onApplicationStart, and some of them are referred to in onSessionStart. However, when I enable ORM, it seems that onApplicationStart isn't running at all and thus my onSessionStart method fails.

It took me a while to figure out this was the issue, generally I'll test by hitting onApplicationStart programatically during development. So it was only after a restart of the service that I found a symptom. Eventually I traced it back to ORM and it's as simple as:

THIS.ormenabled = true; // Error
THIS.ormenabled = false; // Everything peachy

I stripped down the Application.cfc and put some timestamps in the various methods so that I could see what was executing:

<cfscript>
    THIS.Name = "TestyMcTestable"
    THIS.datasource = 'Test';        
    THIS.ormenabled = true;
</cfscript>    


<cfsetting
    requesttimeout="20"
    showdebugoutput="false"
    enablecfoutputonly="false"
    />


<cfset request.pseudo = Now() />
<cfset sleep(1500)>

<cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false">
    <cfset request.application = Now() />
    <cfset sleep(1500)>
    <!--- Return out. --->
    <cfreturn true />
</cffunction>


<cffunction name="OnSessionStart" access="public" returntype="void" output="false">
    <cfset request.session = Now() />
    <cfset sleep(1500)>
    <!--- Return out. --->
    <cfreturn />
</cffunction>


<cffunction name="OnRequestStart" access="public" returntype="boolean" output="false">
    <cfargument name="TargetPage" type="string" required="true" />
     <cfset request.requeststart = Now() />
     <cfset sleep(1500)>
    <!--- Return out. --->
    <cfreturn true />
</cffunction>


<cffunction name="OnRequest" access="public" returntype="void" output="true">
     <cfargument name="TargetPage" type="string" required="true" />
     <cfset request.request = Now() />
     <cfset sleep(1500)>

    <!--- Include the requested page. --->
    <cfinclude template="#ARGUMENTS.TargetPage#" />

    <!--- Return out. --->
    <cfreturn />
</cffunction>

My index.cfm just contains a dump of the request scope. If I remove the orm setting, it all comes back as expected. However with the setting in there, the variable set on application start is missing entirely and it seems onApplicationStart hasn't been run at all.

I'm testing by changing the name of the application inbetween requests, but just to be certain I've restarted the service too.

Am I missing something? Is this documented behavior? I'm running this on Railo - I haven't tested extensively on ACF, but the initial problem occurred there too so I assume it's the same cause.

Can anyone shed any light on this?


Solution

  • Turns out this was a problem with the cfclocation setting. In the original app, it was pointing to an incorrect location. When I stripped the Application.cfc down for testing, I removed this setting - not realising that default behaviour is to traverse the folders from root looking for persistent CFCs. It seems then that the app ran into a problem during that process which bombed out of onApplicationStart, but continued running the other functions in Application.cfc.

    One of the guys on the Railo group identified an issue with using pseudo constructors in non-persistent CFCs that are read by the Hibernate engine. I'm not certain if that contributed to this issue, but it seems likely.