question on populating and ORM in CB

Last question for a little while promise :wink:

the code below seems fine. the issues is with populating.

when i try to populate it get the following message is given....

Error Type: ColdBox.plugins.BeanFactory.PopulateBeanException : [N/A]
Error Messages: Error populating bean model.campaign with argument
CAMP_ID of type class java.lang.String.
Simple values are booleans, numbers, strings, and date-time values.

        /* save campaign test */
        void function saveCampaign(event) output=false{
                var rc = event.getCollection();
                rc.ocampaignbean = campaignService.new();

                populateModel(rc.ocampaignbean);
                campaignService.save(rc.ocampaignbean);

        }

my request structure is as follows...

camp_description: test description
camp_name: test name
camp_id

so as camp_id is empty (as it should be for an insert) populate does
not like it being empty. so i have an issue. to satisfy one I break
the other!

this is what in my model just before i try to populate

ocampaignbean;

component model.campaign
PROPERTIES
camp_id [empty string]
camp_name test name
camp_description test description
company [empty string]

this still does not make sense anyone see why it would be doing this?

Most likely populate is trying to set camp_id to an empty string,
which is causing the error. To verify this do a quick structDelete to
remove the key before calling populate().

.brett

param the id to 0 not ‘’, so the service can give you a new or loaded entity with the passed in ID, and always exclude it from the population.

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

Hi, I did first try to set the ID to 0 before populating it, however
on inserting a new row when doing this I get this error again...

org.hibernate.StaleStateException: Batch update returned unexpected
row count from update [0]; actual row count: 0; expected: 1

you explained this to me last time I understand the error which is why
its so confusing as the id is 100% 0 this time.... here is the rc
scope passed

camp_id 0
camp_name ll
camp_description ll
camp_startDate {ts '2010-07-23 15:57:27'}
camp_endDate {ts '2010-07-23 15:57:27'}
camp_active 1
company [empty string]

function is below any help on this is much appreciated (ps update
works in this function)

        void function saveCampaign(event) output=false{
                var rc = event.getCollection();

                if( len(event.getTrimValue("camp_id")) ){
                        rc.ocampaignbean =
campaignService.get(rc.camp_id);
                }
                else {
                        rc.CAMP_ID = 0;
            rc.ocampaignbean = campaignService.new();

                }
                populateModel(rc.ocampaignbean);
                campaignService.save(rc.ocampaignbean);

I guess you are not understanding me:

// make sure campaign_id = 0 if blank
if( len(rc.campaign_id) ){
rc.campaign_id = 0;
}

// get entity, 0 as id means it will give you a new entity
campaign = campaignService.get( event.getValue(“campaign_id”,0) )

// populate and EXCLUDE the id, you don’t need it
populateModel(model=campaign, excludes=“campaign_id”);

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

Maybe something else is wrong here then

the following does not bring back a new entity

  campaignEntity = campaignService.get(event.getValue("camp_id",0));

I created a new entity with

  campaignEntity = campaignService.new();

this works and I get an empty entity

then I tried to populate from rc and save....

   rc.camp_id = 0;
   populateModel(model=campaignEntity, excludes="camp_id");
   campaignService.save(campaignEntity);

but I still get the error...

org.hibernate.StaleStateException: Batch update returned unexpected
row count from update [0]; actual row count: 0; expected: 1

I am trying to understand, but above looks right, could someone
correct me. other than the line campaignService.get() which should
return a new entity (which for me does not for some reason) it should
still save with the following handler code...

component extends="coldbox.system.EventHandler" output="false"{
  property name="userService" inject;
  property name="campaignService" inject;

       /* save new campaign */
        void function saveCampaign(event) output=false{
                var rc = event.getCollection();
    campaignEntity = campaignService.new();
    rc.camp_id = 0;
    populateModel(model=campaignEntity, excludes="camp_id");
    rc.ocampaignbean = campaignEntity;
    campaignService.save(campaignEntity);

}

}

error message in full....

Application Execution Exception
Error Type: Application : [N/A]
Error Messages: org.hibernate.StaleStateException: Batch update
returned unexpected row count from update [0]; actual row count: 0;
expected: 1
Tag Context:
ID: CFTHROW
LINE: 519
Template: C:\inetpub\wwwroot\cms.yourbrandreality.co.uk\coldbox\system
\orm\hibernate\BaseORMService.cfc
ID: CF_TEMPLATEPROXY

ColdBox Request Structures
Public Collection
camp_active: 1
ocampaignbean:
[cfc1] component model.campaign
PROPERTIES
camp_id 0
camp_name 1
camp_description 1
camp_startDate {ts '2010-07-24 13:36:52'}
camp_endDate {ts '2010-07-24 13:36:52'}
camp_active YES
company [empty string]
METHODS
INIT
function init
Arguments: none
ReturnType: campaign
Roles:
Access: public
Output: false
DisplayName:
Hint:
Description:
GETCAMP_ID
function GETCAMP_ID
Arguments: none
ReturnType: numeric
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
SETCAMP_STARTDATE
function SETCAMP_STARTDATE
Arguments:
Name Required Type Default
camp_startDate Required date
ReturnType: void
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
GETCAMP_ACTIVE
function GETCAMP_ACTIVE
Arguments: none
ReturnType: boolean
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
GETCAMP_NAME
function GETCAMP_NAME
Arguments: none
ReturnType: string
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
GETCAMP_STARTDATE
function GETCAMP_STARTDATE
Arguments: none
ReturnType: date
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
GETCAMP_ENDDATE
function GETCAMP_ENDDATE
Arguments: none
ReturnType: date
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
SETCOMPANY
function SETCOMPANY
Arguments:
Name Required Type Default
company Required any
ReturnType: void
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
GETCOMPANY
function GETCOMPANY
Arguments: none
ReturnType: any
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
SETCAMP_ACTIVE
function SETCAMP_ACTIVE
Arguments:
Name Required Type Default
camp_active Required boolean
ReturnType: void
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
SETCAMP_DESCRIPTION
function SETCAMP_DESCRIPTION
Arguments:
Name Required Type Default
camp_description Required string
ReturnType: void
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
HASCOMPANY
function HASCOMPANY
Arguments: none
ReturnType: boolean
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
SETCAMP_ENDDATE
function SETCAMP_ENDDATE
Arguments:
Name Required Type Default
camp_endDate Required date
ReturnType: void
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
SETCAMP_ID
function SETCAMP_ID
Arguments:
Name Required Type Default
camp_id Required numeric
ReturnType: void
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
GETCAMP_DESCRIPTION
function GETCAMP_DESCRIPTION
Arguments: none
ReturnType: string
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
SETCAMP_NAME
function SETCAMP_NAME
Arguments:
Name Required Type Default
camp_name Required string
ReturnType: void
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
camp_enddate: {ts '2010-07-24 13:36:52'}
event: dashboard.saveCampaign
com_id: 1
camp_startdate: {ts '2010-07-24 13:36:52'}
fieldnames:
CAMP_ID,CAMP_NAME,CAMP_DESCRIPTION,CAMP_STARTDATE,CAMP_ENDDATE,COM_ID,CAMP_ACTIVE
camp_description: 1
camp_name: 1
camp_id: 0
Private Collection
currentroutedurl: dashboard/saveCampaign/
currentroute: :handler/:action/