Check out this threaded discussion on primary-key generation for entity
beans.  Hope it helps!

http://theserverside.com/patterns/thread.jsp?thread_id=4228

- Frank T. Villarreal, Jr.


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 26, 2001 7:54 AM
> To: jboss
> Subject: [JBoss-user] Key generation by random numbers
> 
> 
> As a follow-up to the debate on how to get auto-increment primary
> keys:
> 
> Is it feasible to use a random number generator to generate primary
> keys? I don't really need my records to have steadily increasing keys
> and my number of records will presumably be much smaller than the size
> of my value space (4 billion? depending on data type for prim-key). So
> if I do something along the following when making a new record;
> 
> boolean created = false;
> do 
> {
>    Long key = generateRandomLong();
>    created = ejb.create(key, contents);
> } 
> while (!created);
> 
> 
> (here, ejb.create() takes the primary key of the new record as its
> first param and returns true if success, false if not success)
> 
> My theory is that most of the time, the creation will succeed on the
> first attempt, based on the assumption that number of records is
> insignificant compared to the value space of Long. 
> 
> Pros:
> I don't need to do manual synchronisation with a central
> key-generating bean.
> I don't need to do DB-specific calls to get it to generate for me.
> 
> Cons:
> Unpredictable time use for creation.
> Unusable if number of records becomes significant compared to value
> space of Long.
> 
> I am assuming also that the creation of a random Long is a fast
> process.
> 
> Cheers
>       Bent D
> -- 
> Bent Dalager - [EMAIL PROTECTED] - http://www.pvv.org/~bcd
>                                     powered by emacs
> 
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
> 

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to