Hi!
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(); ct.setNumb(9734); ct.save(); 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(); cr.add(ConstantsPeer.NUMBER,9734); 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 table:
ConstantsDescr (Id, Description) //Id foreign key that refer Constants(Id)
and I want to add a new record in this table like this:
Constants ct=new Constants();
ct.setNumb(9734);
ConstantsDescr cdesc=new ConstantsDescr();
cdesc.setDescription("I don't know!');
ct.addConstantsDescr(cdesc) ;
ct.save();I will receive an error that the foreign key constraint was violated. Somebody can show me a simple solution for this. Thank you!
Levy
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
