CB 3 and CF9 ORM: Mapping for component user not found

Hi, can anyone help.

I am playing around with CB 3 and CF9 ORM. I am not sure its wiring
everything up correctly as I get the message...

Error Messages: Mapping for component user not found.
Either the mapping for this component is missing or the application
must be restarted to generate the mapping.

I have followed the sample app 'task manager' but think i have missed
something..

my handler login.cfc...

  property name="userService" inject="entityService:user";

  /* Index handler */
  function index(event){
    var rc = event.getCollection();
    userService.getAll ();
    event.setView("login/index");
  }

my user.cfc

component output="false" persistent="true"{

  property name="user_id" fieldType="id";
  property name="user_username" notnull="true" type="string";
  property name="user_password" type="string";
  property name="user_email" type="string";
  property name="user_role" type="string";
  property name="user_created" type="date" dbdefault="#now()#";

  user function init() output=false{
    return this;
  }
}

my service

component output="false" singleton{

  userService function init() output=false{
    return this;
  }

  user function getUser(user_id="") output=false{
    if( len(arguments.user_id) ){
      var user = entityLoad("user",arguments.user_id,true);
      if(NOT isNull(task) ){
        return task;
      }
    }
    return entityNew("user");
  }

etc...

app.cfc

  // ORM Setup
  this.ormEnabled = true;
  this.datasource = "testDS";
  this.ormSettings = {
    dbcreate = "update",
    dialect = "MySQLwithInnoDB",
    logSQL = true,
    eventhandling = true,
    eventhandler = "model.ORMEventHandler",
    flushAtRequestEnd = false
  };

That's a error thrown by ColdFusion, rather than Coldbox. Try calling
ORMReload() (don't use this in production!), this tells ColdFusion to
reload all ORM settings (as it caches quite a lot of stuff)

Hi John thanks for the reply.

I tried that in the URL string ORMReload=1 as I spotted it in the
application.cfc but still I get the same message local dev server.

having never used ORM in CF9 I am think its something I have missed or
not understood.

how does it know about my user.cfc object i take it this line in my
handler doesthat by the phrase inject? i.e.

property name="userService" inject="entityService:user";

and should it be entityService? I have tired "userService:user" and
still no joy. from my understanding this means to to inject the user
object into the userService?

it still cannot find the user object the error is....

Application Execution Exception
Error Type: Application : [N/A]
Error Messages: Mapping for component user not found.
Either the mapping for this component is missing or the application
must be restarted to generate the mapping.
ID: CF_CFPAGE
LINE: 348
Template: C:\inetpub\wwwroot\cms.yourbrandreality.co.uk\coldbox\system
\orm\hibernate\BaseORMService.cfc
ID: CF_SUPERSCOPE
LINE: 97
Template: C:\inetpub\wwwroot\cms.yourbrandreality.co.uk\coldbox\system
\orm\hibernate\VirtualEntityService.cfc

Is the service in the same place as the ORM Entity?

It's meant to be entityService, from what I can tell the next part is the
name of the entity it is going to use.

I would highly recommend that if you are using CF9 ORM, learn it outside of ColdBox, and then come back to the integration points.

It’s like trying to eat an apple all in one go - it doesn’t work. You have to take one bite at a time.

Mark

Thanks everyone for the comments.

that's a good point @Mark thanks for the links. using ColdSpring I
took the road the other way around and found it easy seeing demos in
CB outside and then it made sense. but I think I will go and look at
ORM first also. the dependency injection tho is CB error and I think
this is where I am falling here with this, but I agree I need to look
at ORM outside of CB first. if I can just get the dependency to work
here this is where I will start. I understand about objects and using
the model approach and a bit about ORM from my JAVA days.

@ Andrew, yes the model/userService.cfc and model/user.cfc is in the
same folder as the ORMEventHandler which is what CB uses to invoke CF9
ORM from what I understand.

to see if someone can spot anything here is all the files with the
relevant parts...

application.cfc

I decided to run your example.

There are a couple of things that is going on. One the user entity has
errors. So I replaced the properties with ones I knew worked, and found that
your userService has the method getUser instead of get.

Once I fixed those two things up it all worked fine.

get? i dont have a function called get tho. i noticed this on an
example. is this a CB thing does it have to be get?

could you be so kind and post your working user cfc for me to look at?

thanks

That’s right you don't have a get, from what I can tell you need to override
the existing methods.

Here is user.cfc

/**
* User object
*/
component output="false" persistent="true" {

  property name="username" ormtype="string" unique="true"
fieldtype="id";
  property name="password" ormtype="string";
  property name="name" ormtype="string";

  user function init() output=false{
    return this;
  }
}

And here is the userService.cfc

/**
* A service layer that handles all user operations */
component output="false" singleton {

  userService function init() output='false' {
    return this;
  }

  user function get(username="") output='false' {
    if( len(arguments.username) ){
      var user =
entityLoad("user",arguments.username,true);
      if(NOT isNull(user) ){
        return user;
      }
    }
    return entityNew("user");
  }

}//End comp

Of Sparky

cool i have an error I understand now lol. looks like i am now
getting somewhere, i have a bit more to learn on CF9 syntax. its not
so much the methodology I am lucky in that respect from JAVA OO but
the syntax thanks for you help.

That’s ok, it threw me out a bit to because the error return by Coldbox
didn't indicate it was an ORM error.

Of Sparky

Also, I have found that on Mac OS for some reason it was not respecting (coldfusion) my orm entities by name like User. Throwing the same error you showed.

What I did to make it work was use full path notation of where my User was in my app: myApp.model.User

For some reason this worked in windows but not on OS X, something with coldfusion. Another workaround,
was to create a self pointing mapping on the application.cfc to my app and using that instead.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Windows FTW!! ;p