Thanks Carl,

but I don't think that solution will work in a environment with clustered
application servers. When EJB1 on app-server A inserts a record into table "emp"
and then subsequently selects the current value from the sequence, EJB2 on
app-server B may have made a similar insert into the same table between the two
calls from EJB1. The result is that EJB1 retrieves the wrong sequence number.
That's one of the reasons why I want to create and retrieve the primary key in
one go.

// Dennis


"Zetie, Carl" wrote:

> Dennis,
>
> If for any reason you can't get the binding value from the Returning clause,
> you could retrieve it directly with a statement like
>
> select empseq.currval into :bnd1 from sys.dual;
>
> empseq.currval will give you the value you just inserted, without
> incrementing the sequence.
>
> regards,
> Carl
>
> > -----Original Message-----
> > From: Dennis Djenfer [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, August 24, 2001 4:51 PM
> > To: [EMAIL PROTECTED]
> > Subject: [EJB-INT] Primary Key Generation
> >
> >
> > Hi all,
> >
> > One way to generate a primary key, insert a new row and retrieve the
> > generated key in one call is to use the following SQL
> > sentence (at leat
> > in a Oracle database):
> >
> > INSERT INTO emp VALUES (empseq.nextval, 'LEWIS', 'CLARK') RETURNING id
> > INTO :bnd1
> >
> > How do I read the binding variable (:bnd1) that contains my
> > primary key
> > (from column "id") from java? Will the binding variable be
> > presented in
> > the resultset like:
> >
> > primaryKey = rs.getInt(bnd1)
> >
> > or how do I get the value from the Returning clause?
> >
> > If somebody wonder why I don't test it myself it's because I
> > don't have
> > access to a development environment right now
> >
> >
> > // Dennis
> >
> > ==============================================================
> > =============
> > To unsubscribe, send email to [EMAIL PROTECTED] and
> > include in the body
> > of the message "signoff EJB-INTEREST".  For general help,
> > send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> >

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to