Well...

>From the tutorial...

public class Product
{
    /** Artificial primary-key */
    private Integer id;

    /** price per item*/
    private Double price;

    /** stock of currently available items*/
    private Integer stock;

    /** product name*/
    private String name;

    /* Getters and Setters not shown for tutorial */
}
                
CREATE TABLE product
(
    id INTEGER PRIMARY KEY,
    name VARCHAR(100),
    stock INTEGER,
    price DOUBLE
)

   <class-descriptor
          class="org.apache.ojb.tutorials.Product"
          table="PRODUCT"
   >
      <field-descriptor
         name="id"
         column="ID"
         primarykey="true"
         autoincrement="true"
      />
      <field-descriptor
         name="name"
         column="NAME"
      />
      <field-descriptor
         name="price"
         column="PRICE"
      />
      <field-descriptor
         name="stock"
         column="STOCK"
      />
   </class-descriptor>


...
Then after you have stored a product using transction.commit() (you said you were 
using odmg) you should be able to get the unique id/primary key from myProduct.id...

See the tutorials at http://db.apache.org/ojb/user-docs.html for more info :)

Good Luck,
Rob :)


-----Original Message-----
From: Fabiano Fernandes de Souza [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 6 January 2004 11:33 a.m.
To: [EMAIL PROTECTED]
Subject: RE: Getting the Id in insertion time.


Can I ?
How I am stupped! hehehe
:-)

Thank you.

Fabiano.
Em Ter, 2004-01-06 �s 04:48, Coup, Robert Muir escreveu:
> Can't you just look at the primary key field (eg myObject.oid) of the 
> object to retrieve the id value? OJB/ODMG will automatically set this 
> value when the object is persisted/retrieved...
> 
> Rob :)
> 
> -----Original Message-----
> From: Fabiano Fernandes de Souza [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, 6 January 2004 3:01 a.m.
> To: [EMAIL PROTECTED]
> Subject: Getting the Id in insertion time.
> 
> 
> 
> I'm using auto-increment fields.
> The OJB defines the new ID for this fields when I insert a new record. I would like 
> to know how can I know those new ID's values after the insert task using ODMG.
> 
> There's a function that record the object in the database and return 
> the ID value?
> 
> Otherwise, what can I do?
-- 
Fabiano F. Souza
Tecnologia da Informa��o
Estudar Solu��es em Treinamento Corporativo.
(31) 32849294 - [EMAIL PROTECTED]


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

Reply via email to