I have come back to visit this. I know I have asked this question but
still I cannot get this to work. I would like to know if anyone else
can if issues is ONLY with insert not update..
the following code should return a new (blank) entity, however it
doesn't.
rc.camp_id = 0;
// get entity, 0 as id means it will give you a new entity
campaign = campaignService.get(rc.camp_id);
// populate and EXCLUDE the id, you don't need it
populateModel(model=campaign, excludes="camp_id");
the error is "Variable CAMPAIGN is undefined". this suggests to me
that campaign is not created with a new entity if i acuallty put a id
in the rc.camp_id then yes campaign gets created and record get
updated.
so insert does not work, I have also tried to just create a new
entity like so and replaced campaignService.get...
campaignService.new(); but this gives me the error....
"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."
now I have check and check CAMP_ID is 0!
and now the error is on populating "populateModel(model=campaign,
excludes="camp_id")"
I have tried removing camp_id hard coding camp_id to 0 and more.
if (rc.camp_id EQ 0) {event.removeValue("camp_id");}
populateModel(model=campaign);
If you are running the latest BaseORMService, 0 or "" (empty string) will return a "new" entity. But of course, if you have the ID in the rc, then it will populate it with 0 forcing it to try an update and not an insert.
Also, make sure you have a generator set on your entity if you aren't populating the ID yourself. For example.
Ok I have it working now. the issues seems to be in ColdBox when
setting a id to 0 it .save() does not insert but try to update. I have
to remove the id completely to get it to do an insert below works,
however if I remove the id and set it 0 I get an error. for now this
will do. but would be good to know why this is the case.
void function saveCampaign(event) output=false{
var rc = event.getCollection();
if (rc.camp_id EQ 0) {event.removeValue("camp_id");}
I told you, its the population, if you override the ID to 0 then hibernate thinks the ID is 0 and tries to persist it that way. That’s why if you create a single method for insert/update, you need to be careful how you populate your entity.
Sorry Luis, yes you have (twice). I misunderstood you at first as I
read "make sure campaign_id = 0 if blank" but then you said exclude it
from the population (excludes="campaign_id") which makes sense now.
Sometimes I need to be told twice, sorry there were other issues
that threw me on this and confused the situation. like having an out
of date base orm file and stuff that also made me get my wires
crossed. M6 version I downloaded works well now, thanks
well, now thats drummed into me, on with my learning ORM.
Thanks Luis and Curt.
I think Curt knows I can be a pain I used him via your alliance
partner network sometime ago, he was fantastic, more so for putting up
with my stupid questions lol.