> > > On a slightly different subject, how are people dealing with getting
> > unique
> > > key values when they insert records using entity beans? We're trying to
> > use
> > > an entity bean with two fields (keyname and keyvalue). So when a business
> > > service (held in a stateless session bean) requires a new key it makes a
> > > call to the entity bean to get the next key value, analogous to Oracle
> > > sequences. Does anyone have any views on this approach, will it work ??
> > > regards
> > > Bhupesh Wagjiani
> > > GamCom Solutions Limited
> > > [EMAIL PROTECTED]

> This won't work if there are multiple containers involved.
>
> Here is one way I have found that works.  Create a table on the database to
> hold a key value.   Then, create a stateless session bean with a method
> (marked REQUIRES_NEW) that will give you a new primary key.  Now, when you
> need a primary key, the stateless session bean will go the database,
> determine what key is next, increment the key on the db, and then give you
> back the primary key.  Since this is in a separate transaction, it won't
> block while other work is going on.
>
> To reduce the number of database accesses, have the stateless session
> reserve a 'block' of keys at one time.  Have the session give them out one
> at a time, and only go to the database when you need more.
>
> HTH
>
> Jonathan Baker
> Internet Applications Division


<Vendor>
With GemStone/J you can make use of PCA which works across multiple Gs/J
containers. The idea is to get a cpunter bound into the PCA (which also
provides a shared memory cache) and increment it everytime you need a
new key. It's fast, and atomic for each client. Plus it does not violate
your application transaction semantics.

By the way, if I may, what app server are you using?
</Vendor>

--
Harsh
GemStone Systems
"If a dog will not come to you after having looked you in the face,
 you should go home and examine your conscience" -- Woodrow Wilson

===========================================================================
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".

Reply via email to