Hi folks,
I am using Torque-generated classes together with MySQL (gjt driver) and its
autoincrement feature within my app.
How do I retrieve the newly created primary key after a save() for storing
object associations?
What I do is the following (Logentry and LogentryProcess are Torque-generated
classes):
public void store(Logentry entry) {
try {
entry.save();
log.info("stored entry under key "+entry.getId());
LogentryProcess assoc = new LogentryProcess();
assoc.setLogentryId(entry.getId());
assoc.setProcessId("4"); // for testing
assoc.save();
log.info("stored association");
}
The schema definitions of the tables are
<table name="logentry">
<column name="logentry_id" javaName="Id" required="true"
autoIncrement="true" primaryKey="true" type="INTEGER"/>
<column name="name" required="true" size="255" type="VARCHAR"/>
[...]
</table>
<table name="logentry_process">
<column name="logentry_id" required="true" primaryKey="true"
type="INTEGER"/
>
<column name="process_id" required="true" primaryKey="true"
type="INTEGER"/>
<foreign-key foreignTable="logentry">
<reference local="logentry_id" foreign="logentry_id"/>
</foreign-key>
[...]
I would expect entry.getId() to return the new key id. But it is null.
How do I get that information? Or do I have to use other techniques of storing
object associations?
TIA,
Erich
--
Dr. Erich Meier, Software Process Improvement
method park, Wetterkreuz 19a, 91058 Erlangen, Germany
Tel. +49-9131-97206-316 mailto:[EMAIL PROTECTED]
Fax. +49-9131-97206-200 http://www.methodpark.de/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]