Environment:
Struts 1.12b
PostgreSQL 7.2.3
Torque 3.0 rc-2
JDK 1.4.0
Situation:
I am trying to use Torque for Struts application. The save() method of each torque class works fine.
In one situation, I have to create an entry first, then create multiple entires in another table with foreign keys to the primary key of the first entry. I can't find a good way to do it.
Structure:
Magazine object (Contains magazine info)
Article object (each article inside of Magazine object, and has a foreign key mapped to the primary key of the magazine. Magazine class corresponding TorqueMagazine class, and Article class has a corresponding TorqueArticle class. The magazine object is contained in ActionForm as a bean.
Hi everyone,
save() method doesn't return the primary key when inserted. I didn't know this, so now I have a problem.
I get "foreign key integraton violation" when I call save method of torqueArticle. It says that magazine table doesn't contain the primary key that is referenced by a foreign key of the torqueArticle object.
MagazineBeanHelper.save(actionForm.getMagazine());
pageKey = actionForm.getMagazine().getMagazineID();
for(int i =0; i < actionForm.getMagazine().getArticle().size(); i++) {
((ArticleBean)actionForm.getMagazine().getArticle().get(i)).setMagazineID(pageKey);
PagePartBeanHelper.save((ArticleBean)actionForm.getMagazine().getArticle().get(i));
}
Something like this.
And above code doesn't work after inserting a magazine entry. MagazineBeanHelper create torqueMagazine object, fill it with magazine object, and calls save() method . save method doesn't return the primary key, but I thought at least set the newly created primary key to the torqueMagazine object.
It didn't.
The only other way I can think of is to do "saving magazine", "getting that magazine right away", get the primary key of the magazine", "use the key to store each article objects". Or I have to use doInsert() of Peer class instead.
Then again,
how do I get the newly stored entry?? I can't get the primary key. The system is accessed concurrently by multiple users, so getting the latest torqueMagazine doesn't always work.
Or before that,
now I think that there must be a smarter way to do this!
Does anybody know??
I appreciate any suggestion or thought.
Thank you in advance.
[ December 05, 2002: Message edited by: Shin Hashitani ]
[ December 05, 2002: Message edited by: Shin Hashitani ]