[EMAIL PROTECTED] writes:
> On Sep 27, Rickard Oberg quoth:
>
> > > We have some CMP beans that generate their own primary keys using sequence
> > > numbers, however they aren't acquired from an external source. What is
> > > passed into the ejbCreate methods is simply data to be stored. It never
> > > occured to us that we were doing anything special. The big difference,
> > > however is that the ejbCreate method must return the primary key and since
> > > we generate it internally in the method it's there for us to return.
> > >
> > > IMHO, sounds like BMP is what you need to use.
> >
> > Not following .Why is BMP a must? (ie. you can do something similar with
> > CMP, just refactor the key creation to a stateless session bean).
>
> If you are using a DB specific feature to generate your primary keys,
> unless you invoke jdbc directly in your ejbCreate (thereby making your cmp
> bean a de-facto bmp bean) you have no way of knowing what primary key to
> return to the container. While moving the jdbc code to an SSB will avoid
> having a hybrid (and noncompliant?) bean, how do you have the container
> skip the attempt to insert a record after ejbCreate and only update the
> row created by this SSB?
As noted previously, this is not possible with the 'auto-increment'
type of mySQL, but only with the sequence facility of Oracle,
PostgreSQL and the like. These are just sequences of numbers:
SELECT NEXTVAL( 'a_sequence' ); /* Postgres */
SELECT a_sequence.nextval FROM DUAL; /* Oracle */
will give the next value in the sequence, which you can use for
whatever you like. So the SSB doesn't have to create a row, it just
returns a key for ejbCreate to use.
I prefer the idea of using an MBean to an SSB, which is then pluggable
into any JMX architecture, but (a) that's just my opinion and (b) I've
never got it to actually work <grin sheepishly>.
> For our application where we internally create our primary keys we aren't
> using a database feature to do so.
How do you guarantee that they are unique across server instances?
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]