db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: many-to-many sample code
Date Wed, 19 Apr 2006 16:44:54 GMT
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:
>   <table name="appuser" description="User Table">
>     <column name="user_id" required="true" primaryKey="true" 
> type="INTEGER" description="User Id" />
>     <column name="login" required="true" type="VARCHAR" ize="128" 
> description="Login"/>
> ...
>  </table>  <table name="application" description="Application Table">
>     <column name="application_id" required="true" primaryKey="true" 
> type="INTEGER" description="Application Id" />
>     <column name="name" required="true" type="VARCHAR" size="128" 
> description="Name"/>
> ...
> </table>
>   <table name="user_application" description="User Application Table">
>     <column name="user_id" required="true" primaryKey="true"  
> type="INTEGER" description="User Id" />
>     <column name="application_id" required="true" primaryKey="true" 
> type="INTEGER" description="Application Id" />
>     <foreign-key foreignTable="appuser">
>       <reference local="user_id" foreign="user_id"/>
>     </foreign-key>
>     <foreign-key foreignTable="application">
>       <reference local="application_id" foreign="application_id"/>
>     </foreign-key>
>   </table>
> 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

View raw message