Hi Michael.
A simple way is to use facilities provided by Oracle itself.
eg.
CREATE SEQUENCE mysequence;
will give you a sequence initialized to 1, increment by 1. You can alter these
with the ALTER SEQUENCE if you need to one time (eg. you already have allocated
values past 1, and want your sequence to start higher.
and
SELECT mysequence.nextval FROM dual
('dual' is a dummy table) will give you the next value.
Oracle guarantees that it will never dish out the same one twice.
You're welcome.
David.
Michael Pikounis wrote:
> Hello all!
>
> I am looking for a good way to generate primary keys for my entities and I
> was wondering if there is a "standard" way.
>
> Each of my entities maps to an oracle table, and I would like each table to
> have its own key sequence.
>
> One way I can think of is to query oracle for the next key in the table's
> sequence prior to .creating() my entity bean but that seems like a great
> overhead given that I would need to go to the database twice for every
> insert I do (one to get the key, and one to insert it).
>
> Another way would be to ask oracle for a key as a starting point and then
> increase it until I have done all my inserts (for a transaction?) and then
> tell oracle the new value for the sequence. This may be more efficient but I
> am not sure how safe it is given that while I am increasing my sequence some
> other process may query oracle for the next key (in which case we would both
> use the same).
>
> All ideas are very welcome!
>
> Michael
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
> ===========================================================================
> 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".
--
David Bullock
Project Manager - Strategic Applications
[EMAIL PROTECTED]
"It's no use saying 'We are doing our best.' You
have got to succeed in doing what's necessary."
...Winston Churchill
LISAcorp
http://www.lisa.com.au/
Adelaide Sydney
-------------------- ------------------------
38 Greenhill Rd Level 3, 228 Pitt Street
Wayville S.A. 5034 Sydney NSW 2000
PH +61 8 8272 1555 PH +61 2 9283 0877
FAX +61 8 8271 1199 FAX +61 2 9283 0866
-------------------- ------------------------
===========================================================================
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".