[EMAIL PROTECTED] wrote:
> 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);
One problem with using random numbers is that they're not guaranteed to
be unique--two calls to generateRandomLong() can return the same value.
Another problem is that computing the next random number might be
relatively computationally expensive. I'd say serial numbers are better.
--
Richard Kasperowski (mailto:[EMAIL PROTECTED])
Tel: 617-576-1552, Fax: 617-576-2441
http://www.altisimo.com/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user