db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kintzel Levente" <kintzel.leve...@softech.ro>
Subject Autoincrement
Date Wed, 23 Feb 2005 13:09:22 GMT


I have a table with an id field autoincrement and an another field (numb  
for example). The table name is Constants. Now I add a row in this table:

   Constants ct=new Constants();
   System.out.println(ct.getId()); //returns always 0

In the table ct will have associated the auto generated ID too. How can I  
obtain its value?

Criteria cr=new Criteria();
List lst=ConstantsPeer.doSelect(cr);
ct=(Constants) lst(0);
System.out.println(ct.getId()); //returns the correct id

There exist a simpler solution? If the Number field is not unique then I  
have no guarantee that I obtain the correct value...

An another question... If I use the Id field as a foreign Key in another  

     ConstantsDescr (Id, Description) //Id foreign key that refer  

and I want to add a new record in this table like this:

   Constants ct=new Constants();
   ConstantsDescr cdesc=new ConstantsDescr();
   cdesc.setDescription("I don't know!');
   ct.addConstantsDescr(cdesc) ;

I will receive an error that the foreign key constraint was violated.  
Somebody can show me a simple solution for this. Thank you!


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

View raw message