wellll,
I had the same problem. I overcame it with "select
LAST_INSERT_ID()" as I use MySQL to get the last
inserted ID. If you use SQL server you can user the
$$identity variable or if using Oracle -> the current
number of the suquence you use.
It's possible also to use the MAX(ID) but it's not so
safe.
If you use IDBroker for the ID insertion it should be
better as you can get the last ID at any time you want
but.... as I know it doesn't work safe with databases
that does not support transactions(MySQL for example).
So... I still wonder if somebody has implemented this
feature to use the relevent functions to get the last
insertted ID...

Hristo Kosev
--- Andrea Papotti <[EMAIL PROTECTED]> wrote:
> I have two tables like:
> 
> <table name="REQUEST">
>     <!-- substitution requests (header) -->
>     <column name="ID"          type="INTEGER"    
> required="true"
> autoIncrement="true" primaryKey="true"/>
>     <column name="SRC"       type="INTEGER"    
> required="true"/>
>     <column name="DST"       type="INTEGER"    
> required="true"/>
>     <column name="DATE"    size="8"  type="VARCHAR" 
>    required="true"/>
>     <column name="NOTE"    size="80" type="VARCHAR" 
>    required="true"/>
>  </table>
> 
>   <table name="DETAILS">
>     <!-- substitution requests (detail) -->
>     <column name="ID"                 type="INTEGER"
>     required="true"
> autoIncrement="true" primaryKey="true"/>
>     <column name="REQUEST"    type="INTEGER"    
> required="true"/>
>     <column name="CODE"           type="INTEGER"    
> required="true"/>
>     <column name="QTY"              type="INTEGER"  
>   required="true"/>
>   </table>
> 
> which are related via REQUEST.ID = DETAILS.REQUEST
> 
> 
> I need to write 1 record in "REQUEST" fallowed by
> many records in "DETAILS",
> 
>         try
>         {
>             Richieste header = new Request();
>             header.setSrc( src_code );
>             header.setDst( dst_code);
>             header.setDatel( today() );
>             header.setNote( note );
>             header.save();
> 
>             header_id = 
> header.getId().getBigDecimal().intValue();
>         }
>         catch (Exception e)
>         {
>             context.put("error", "header: " +
> e.toString());
>             return;
>         }
> 
> 
> fallowed by code to write records in "DETAILS".
> 
> BUT
> 
> header_id =
> header.getId().getBigDecimal().intValue();
> 
> fails bacause header.getId() returns null.
> 
> the question is:
> 
> I must re-read the record just saved (with the
> immediatly previous
> statment), or there is a method to obtain the value
> of the primary-key just
> afer the .save() call?
> 
> Re-read the record could be a problem, because the
> only unique field is
> right the ID.
> 
> tia, Andrea  =8-)

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com

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

Reply via email to