Link to home
Start Free TrialLog in
Avatar of Bobby X
Bobby XFlag for United States of America

asked on

Could not find object method in ColdFusion...

Hi,

I have an instance of a ColdFusion object created and stored in session scope the first time during user's session start and persists over the lifespan of the session (See code below). The problem is that every time I introduce a new method to the component and deploy the method to Production, my users are receiving the error "Could not find method 'getProductInfo'..." This is because the users' session still persists and therefore all the methods and properties of the object are still referring to instance of object in the session that was created right before code deployment.

<cfparam name="session.myObject" default="#createObject('component','myComponents.Products').init(request.someVariable)#">
<cfset variables.result = session.myObject.getProductInfo(request.CustomerID)>

How do I prevent/resolve this problem?

NOTE: I could have used local variable to store the object, but I don't want to do that because doing so would require the object to be created on every page load. And I don't want to store the object in application variable neither as it presents other problems.

I'm using CF 8.

Many thanks in advance.
Avatar of gdemaria
gdemaria
Flag of United States of America image

Typically, I do this in the application scope, which is much easier to rebuild on demand.   You just add a secret URL variable such as  &reloadAppVars=1 and that is tested in the application.cfc file and forces the reload.

In your case, you really can't do this as you have many session variables already loaded.  The user must logout and log back in.  Which basically means you have to do you loads to production at night and kick out all users when you do it forcing the session variables to refresh.   You can do that by changing the application name a little such as "myApp" to "MyApp1"  or restarting the CF service.
SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops.. mid-air post collision.

I think my suggestion would work too. But if it's anything more than a single component, I'd probably go with gd's suggestion of a complete reset.  Starting with a clean slate is almost always less problematic. If only because it's easy forget dependencies and end up causing problems because you forget to reload X when you reloaded Y.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bobby X

ASKER

gdemaria,

Should it be this way instead?

 <cfif dateCompare(request.componentsUpgradDate, session.ComponentsLastLoaded) gt 0>
         <cfset methodToReinitializeSessionComponents()>
 </cfif>

Meanting if request.componentsUpgradDate is later than session.ComponentsLastLoaded, then we re-init the session. Otherwise, the code will be reinitializing the session on every page load after user's session times out and begins a new session?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial