One possibility is to grab a 'chunk' of ID's at one time. e.g. client
asks for an ID, database counter is incremented by 100, and the client
has effectively reserved ID's 1-100 for its use. Until it uses up this
batch of IDs, the client need not hit the database again to request a
new ID. When it does, it gets given another batch etc. etc. This can
vastly reduce the number of expensive database operations required. The
size of these chunks obviously depends on your
application/performance/memory constraints and so on.
Another approach I've seen used successfully is to just pick a random
integer as an ID, and attempt to use it. If there already happens to be
a row with the same primary key, the database throws an Exception, and
you simply generate a new random number, and try again etc. etc. In
practice, unless you have hundreds and hundreds of millions of rows,
primary key clashes are very unlikely, so performance is not a problem.
Cheers
Alasdair
> Hi All,
>
> I have a question regarding Creating CMP Entity EJBs.
> For several of our Entities, we use a sequence number generated by our
> database (Oracle) as a primary key.
> The problem is that our ejbCreate() method expects a primary key when
> invoked. Also, the persister generated create methods appear to be called
> before even the first line of the bean's ejbCreate().
>
> To get around this, at the controller level, we were able to create a
> separate Connection, query the database for the next sequence number, close
> the connection, and then call the EJBHome Create() method passing in the
> sequence number.
> Although it works, this approach seems very clumsy and slow. There's got to
> be a better way,
> Perhaps where we don't even need a separate database connection.
>
> I assume many of you are also using database generated sequence numbers.
> Have any of you run into this same problem? Any ideas for a more elegant
> solution?
>
> Thanks,
> Dan
>
> ===========================================================================
> 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".
===========================================================================
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".