db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eustache <eustache.fel...@idilia.com>
Subject many-to-many sample code
Date Wed, 19 Apr 2006 16:10:40 GMT
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





---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message