I think this is happening because you have not set the primary key
value for the user object. You only set login and not user_id. In
addition, you may have to save the new user object for the
getPrimaryKey() methods to recognize this as a valid key. After all,
until you save it, you don't know if the user_id value meet all
your DB key criteria (like being unique) unless you try to save it.
It's basically the same methodology as native SQL. You have to
create the real DB records with valid keys in the foreign key
tables before you can fill in the mapping table. And then if
you need to tie this record back, you need to update and save
the user object so the newly generated key is available.
> -----Original Message-----
> From: Eustache [mailto:eustache.felenc@idilia.com]
> Sent: Wednesday, April 19, 2006 12:11 PM
> To: torque-user@db.apache.org
> Subject: many-to-many sample code
>
>
> Hi all, I am new to Torque,
> Thanks for your help in advance,
> I couldn't find any sample of many to many relationship nor a
> simple way
> to search the archive, so here is my problem:
>
> I have this schema:
>
> type="INTEGER" description="User Id" />
> description="Login"/>
> ...
>
> type="INTEGER" description="Application Id" />
> description="Name"/>
> ...
>
>
> type="INTEGER" description="User Id" />
> type="INTEGER" description="Application Id" />
>
>
>
>
>
>
>
>
> And my code:
> Application administration = new Application();
> administration.setName("Administration");
> administration.save();
>
> Appuser user = new Appuser();
> user.setLogin("tomcat");
>
> UserApplication user_app = new UserApplication();
> user_app.setAppuser(user);
> user_app.setApplication(retrieve_2ag);
> user.addUserApplication(user_app);
>
> user.save();
>
> Issues an exception (why ?):
> org.apache.torque.TorqueException: Database insert attempted without
> anything specified to insert
Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed. If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately. Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited.
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org