function is not of type error

I am trying to use code generated from the PU36 code generator and the
templates provided with Coldbox 2.6.1.
My table is called users - from an edit form, I want to save the
results. A few lines of code from the users handler:

    //get a new users bean
    ousersBean = oService.getusers(0);

    //Populate the bean
    getPlugin("beanFactory").populateBean(ousersBean);

    //Send to service for saving
    oService.saveusers(ousersBean);

The returntype for getUsers in my service component is "ANY". Right
before I call the saveUsers(), I dump it and see the component is
model.decorator.users which extends transfer.com.TransferDecorator. So
everything looks good to me at the point of saving but I get this
error, more of which is pasted below. What am I missing here?

Frank

Frank,

If you look at the <cfargument> for your saveUsers() method it will
probably say type="model.service.users". But the object you are
passing in is type="model.decorator.users". So you need to either
change that type to model.decorator.users or to ANY.

Jason

Wait, I take that back. You may need to change it to
type="transfer.com.TransferObject" or to type="any". The object that
is ultimately being passed in is a TrO, even though it is being
decorated with model.decorator.users, at least in my apps that's the
way it works.

Jason

Hi Jason,

Thanks for the help. Changing the argument type to
"transfer.com.TransferObject" or "any" on the saveUsers() seems to
work. Makes sense for the formaer because that is what the argument is
at that point which is a Transfer object. Think I will change that in
the PU36 template for the save methods.

On to the next issue, transfer is trying to do an insert now instead
of an update. I have ensured the PK is not 0 when it is sent to the
save method. Even though it has a value, transfer is trying to insert
and not update, and it is trying to insert the PK which is auto
increment in the DB, so I must have something configured wrong.

Dan

Look in your Transfer config file. generate attribute must contain false.
e.g. <id name="companyId" column="com_id" type="numeric" generate="false" />

Ernst

That is what I have:

<id name="userID" type="numeric" generate="false" />

But it is definitely try to insert the userID as one of the params.

INSERT INTO users
(userName,password,firstName,lastName,email,notes,lastLogin,lastLoginIP,createdBy,createdOn,userID)
VALUES ( (param 1) , (param 2) , (param 3) , (param 4) , (param 5) ,
(param 6) , (param 7) , (param 8) , (param 9) , (param 10) , (param
11) )

Param11 is uderID:
(param 11) = [type='IN', class='java.lang.Double', value='1.0',
sqltype='cf_sql_float']

So transfer sees the userID has a value of 1

It's hard to say where the problem is without seeing more of your code
and your config file, and asking about your database. Is useriD set to
auto-increment? How are you originally creating the TrO in your
oService.getUser() method?

Also, you might want to consider asking or searching at the Transfer
group. They might have an answer more quickly. I am still pretty new
to Transfer.

Jason

I just came across this. It may answer your question.

Primary Key Control with Transfer (Transfer Tutorial Part 2)

Jason

Take a look at the ColdBox Security Sample App.
It contains an complete example of Transfer and ColdBox.

Ernst

I was thinking about that yesterday because originally when I
generated the code and ran it, I did not have the auto increment set
for the table. I do now - cleared the definition files and cycled the
service with the same result.

But transfer is not trying to generate the ID, it sees I have a value,
so I wonder why it is trying an insert instead of an update.
Here is my save method:
                var rc = event.getCollection();
    var oService = getPlugin("ioc").getBean("usersService");
    var ousersBean = "";
    ousersBean = oService.getusers(0);
    getPlugin("beanFactory").populateBean(ousersBean);
    oService.saveusers(ousersBean);

And the saveUsers():
  <cffunction name="saveusers" access="public" output="false"
returntype="void">
    <cfargument name="users" type="transfer.com.TransferObject"
required="true" />
    <cfset variables.transfer.save(arguments.users) />
  </cffunction>

I looked at the link regarding the PK's but did not find anything new
there. Thanks

Do you use variables.transfer.get() or variables.transfer..new() ?

If you want Transfer to update somthing, you first need to
get/instantiate a Transfer object.
Don't forget to pass in an ID.
Transfer will return a populated Transfer Object if it finds a record
in the database.

Use getMemento() on your TransferObject, so sth like this:
<cfdump var="#myTransferObject.getMemento()#" />

If your Transfer Object ID has a value of 0 or an ID which doesn't
exist in the DB, it creates a new row in the database.

Look in the Transfer Docs to learn how transfer works.

Ernst

Do you use variables.transfer.get() or variables.transfer..new() ?

Here is my function for getting the user. Maybe the return type is the
problem:
  <cffunction name="getusers" access="public" output="false"
returntype="any">
    <cfargument name="userID" type="Numeric" required="true" />
    <cfreturn variables.transfer.get("users.users",arguments.userID) />
  </cffunction>

If you want Transfer to update somthing, you first need to
get/instantiate a Transfer object.
Don't forget to pass in an ID.
Transfer will return a populated Transfer Object if it finds a record
in the database.

Use getMemento() on your TransferObject, so sth like this:
<cfdump var="#myTransferObject.getMemento()#" />

If your Transfer Object ID has a value of 0 or an ID which doesn't
exist in the DB, it creates a new row in the database.

I had previously ensured my object was populated properly with the
getMemento() right before the call to transfer.save. If I dump the
object right before the save I see the object is model.decorator.users

Matt Quackenbush was able to find my issue over on the transfer list.

The resolution had to do with my misunderstanding that if the ID value
in the object was non-zero, transfer would do an update versus an
insert, when in fact it is the isPersistent flag in the object.

So I changed this:
oclientBean = oService.getclient(0);

To this:
oClientBean = oService.getClient(event.getValue("clientID", 0));

Who is the author of the Coldbox Illudium templates that come with the
coldbox package that I can send some suggestions to for changes?

Thanks everyone