Rickard Oberg writes:
> > > Is there any way to make a CMP entity EJB use a automatic value as its
> > > primary key, so that in the create method you dont have to pass it the
> > > primary key value ?
> > >
> > > If anyone has any idea I would really appreciate !
> >
> > Hmmm. The closest I've come to this is to write an MBean which
> > generates keys from sequences in a database. Then in ejbCreate you
> > connect to the MBean and get a new PK from it...
>
> How about this:
> One CMP bean with primary key being the bean name and an additional field
> currentId. It has a method nextId(int batchSize) which returns currentId and
> also adds batchSize to currentId. This can then be called by a stateless
> session bean that has a method nextId(String beanName), which calls the CMP
> bean to get the next id. It stores the next id from the CMP bean, and can
> then internally increment this counter batchSize times.
>
> Anyone has any objections? Would be pure EJB, and fast (only hits DB for
> every batchSize key generation request).
The exact algorithm we've used is to split the keys generated into two
sections. The low bits are from an internal couter maintained by an
instance of the key generator, and the high bits are from a database
sequence. The high bits are only refreshed when (a) the key generator
stars (b) the low bits rollover (c) it is requested to by a
client. This was you always get unique keys from multiple instances of
the key generator.
Tom
--
Tom Cook - Software Engineer
"We rarely find that people have good sense unless they agree
with us."
- Francois, Duc de la Rochefoucauld
LISAsoft Pty Ltd - www.lisa.com.au
--------------------------------------------------
38 Greenhill Rd. Level 3, 228 Pitt Street
Wayville, SA, 5034 Sydney, NSW, 2000
Phone: +61 8 8272 1555 Phone: +61 2 9283 0877
Fax: +61 8 8271 1199 Fax: +61 2 9283 0866
--------------------------------------------------
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]