Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: saving object using sequence as ID, help!
On Fri, 05 Apr 2002, hxzhang_at_binary-solutions.net wrote:
>
> I have a table with each row corresponds to a javabean object. The
> objects don't necessarily have a primary key, so i use a sequence
> number as its primary key, and a trigger to assign the sequence number
> to its ID column when a new object is inserted into the database.
>
> However, after I insert the object into the table, how can i know the
> object's ID in the table? If I simply do a "..._seq.cur_val", it is
> not safe when multiple users can access the database and save their
> javabean into it at the same time.
curr_val is unique per session. Try it out.
SQLPLUS1> select ..._seq.next_val from dual; SQLPLUS2> select ..._seq.next_val from dual; SQLPLUS1> select ..._seq.curr_val from dual; SQLPLUS2> select ..._seq.curr_val from dual;
Do you see that both sessions are quaranteed a unique sequence number? Try it with three, or four or five sqlplus sessions. Oracle guarantees a unique sequence number.
-- Galen deForest Boyer Sweet dreams and flying machines in pieces on the ground.Received on Sun Apr 07 2002 - 20:55:23 CDT