I think your problem is that you didn't specify the autoincrement method 
(Turbine's ID-Broker, autoincrement, sequence). Possible values are:
- autoincrement
- sequence
- idbroker
- none

Default is none. That's why you get null... Your schema should be 
something like:

<table name="logentry" idMethod="autoincrement">
    <column name="logentry_id" javaName="Id" required="true"
                primaryKey="true" type="INTEGER"/>

.... (and so on...)

Aleks

P.S.: The OM class will return a NumberKey object! If you want the 
integer value then do something like 
entry.getId().getBigDecimal().intValue()

Erich Meier wrote:

>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
>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to