Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

"Object passed is not a valid entity" DAO cffunction can't recognize cfargument type of ORM VO

New Here ,
Apr 07, 2010 Apr 07, 2010

Question about seemingly simple issue that's been confounding me for days.  I can't call a function to save a VO (a CFC using CF9 ORM).

Here's my setup

- PersonDAO.cfc -

<cffunction name="getAll" access="remote" returnType="PersonVO[]">    
    <cfscript>
        return entityLoad("PersonVO");
    </cfscript>

</cffunction>

<cffunction name="save" access="remote">
    <cfargument name="person" type="any" required="true">       
    <cfscript>
        entitySave("person");
    </cfscript>
</cffunction>

-PersonVO.cfc-

<cfcomponent alias="com.foo.PersonVO" persistent="true" table="PERSON">
    <cfproperty name="pk" fieldtype="id" ormtype="long" column="PERSON_PK">
    <cfproperty name="employeeId" column="EMP_ID">
    <cfproperty name="userLoginId" column="USR_LOGIN_ID">
</cfcomponent>

When I call getAll() either through another test.cfm file or through Flex 3 remoting, everything works just fine, and a list of strongly-typed objects is returned.  I can even manipulate the persistent objects within test.cfm and they automatically save to the DB without issue.  This implies that my Application.cfc, ORM settings, datasource settings, and CFCs are configured correctly.

But save does not work!  When calling it from test.cfm, I get "Object passed is not a valid entity".  When calling from Flex I get a "coldfusion.runtime.CfJspPage$NoSuchTemplateException" saying it couldn't find the object.  Why won't this function accept an entity as a parameter?  I tried specifying the type, but it can never find that type.  Although I can create new ones, and factory.getAllClassMetadata() lists the class I'm trying to reference.  What gives?!

-- Likely Related Issue (but I don't care if this one is solved)  --

Something funky is going on with my path/package structures.  I can only get EntityLoad to work when the DAOs and VOs are all in the same directory, and they're referenced by their class name alone (not package name or alias name).

  • So my entity is located at C:/ColdFusion9/wwwroot/MyApp/com/foo/PersonVO.cfc
  • In my DAO, returnType="PersonVO" works just fine so long as the DAO is in the same directory as the VO
    • The DAO cannot find the object type when it is in another directory
  • The following return types on the DAO cffunction above don't recognize the object
    • com.foo.PersonVO
    • MyApp.com.foo.PersonVO
  • Even if I created a mapping with a virtualName of "cfcs" and point it at "C:/ColdFusion9/wwwroot/MyApp/com/foo", the following won't work
    • cfcs.PersonVO
    • MyApp.cfcs.PersonVO
  • Every combination of the above, where PersonVO.cfc is in placed in wwwroot, then when PersonVO.cfc is placed in wwwroot/MyApp

I spent almost a week troubleshooting this with no success.  This sounds like a crazy question, but does CF9 ORM object support directories?!  Non-ORM objects work just fine.  I tried altering every possible cfcomponent and Application.cfc property that makes sense, but could not find a way to reference VOs in another directory.  Any help?  Especially if this is related to the first issue.

875
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2010 Apr 08, 2010
LATEST

This problem was half-solved in another thread (2722116)

Here's the clarification of why the code was breaking on parameter input:

  • cfargument types attributes require fully-qualified class names
  • cffunction returnType attributes usually require fully-qualified class names, but will work with just class names for cfcs in the same directory
  • ORM functions do not recognize fully-qualified class names, and require just class names

Here's the other half of the problem (and the cause of the 'not a valid entity' error):

  • I had quotes around my variable, and was therefore trying to perform entitySave on a string!

Here's the fixed code (with changes bolded😞

- PersonDAO.cfc -

<cffunction name="getAll" access="remote" returnType="com.foo.PersonVO[]">   

    <cfscript>
        return entityLoad("PersonVO");
    </cfscript>

</cffunction>

<cffunction name="save" access="remote">
    <cfargument name="person" type="com.foo.PersonVO" required="true">      
    <cfscript>
        entitySave(person);
    </cfscript>
</cffunction>

Message was edited by: NickMatelli to add the part about there being quotes around the variable name

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources