One way to do this would be to have the number supplied by the database
lookup incrementing in larger steps
e.g. Process A asks DB for a sequence number ---> 1000
Process A: Add entity 1000
Process A: Add entity 1001
Process B asks DB for a sequence number --> 2000
Process A: Add entity 1002
Process B: Add Entity 2000
Process B: Add Entity 2001
Process A: Add entity 1003
Process B: Add Entity 2002
etc.
When you've used up 'step' allocated sequential numbers, you ask the DB for
the next sequence number. This is a reasonable trade-off between
performance and concurrency. Of course, the choice of a value for the step
size is a matter of performance tuning ...
Hope this helps
Alasdair
Michael Pikounis
<mpikounis@HOTMAI To: [EMAIL PROTECTED]
L.COM> cc:
Sent by: A Subject: Primary Key Generation
mailing list for
Enterprise
JavaBeans
development
<EJB-INTEREST@jav
a.sun.com>
12/01/00 10:00
Please respond to
A mailing list
for Enterprise
JavaBeans
development
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".
===========================================================================
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".