This could be an option in CMP perhaps.

-----Original Message-----
From: Aaron Mulder [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 08, 2000 11:51 AM
To: jBoss
Subject: Re: [jBoss-User] Implementing an entity bean to access an
Oracle sequence


On Fri, 8 Dec 2000, Peter Schauss wrote:
> Is it possible to access an Oracle sequence with an entity
> bean using CMP or must I use BMP?
>
> If anyone has done this, can you post some sample code?

        There have been several extensive discussions about this on the
mailing list.  I'll repeat a few of the points, but you can also look
through the archives:

 - There's not way for CMP to "do it for you" since there's so much
variance across DBMSs

 - There are a number of ways to generate unique keys without hitting the
sequence every time (grab a block of numbers, use some bits from the DB
and some bits from the app server, etc.)

 - You can write an MBean that gets IDs from the sequence, so when a bean
wants an ID it gets the generator MBean from JNDI and then asks for it.
I think Rickard wrote an example of this that is in CVS somewhere (test
beans?) - but it may require minor changes if you're using JBoss from CVS
instead of JBoss 2.0.  This is probably the most elegant solution, and can
even incorporate the point above, but requires some familiarity with JMX
MBeans, the JBoss config files, etc.

 - You can write a method in your CMP bean that gets the value from the
sequence (using BMP-style DB calls).  Then in your ejbCreate, call that
method to generate the ID and put it in a field, which will be persisted
via CMP after the ejbCreate returns.  Whether you prefer this option or
the previous one probably depends on how many sequences you're planning to
use - this would be the "quick and dirty" solution.

Aaron



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to