Hello Luis...
That's what we're currently using but instead of implementing it in a session bean, we
implemented the query in a private method of the particular entity bean using it.
I'm asking this question cause I thought that there's something wrong with the
implementation. I thought I'm missing something cause articles like the one I read are
supposedly written by experts.
Jerson
--- Luis Canals <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I think your right: it doesn't works because two (or more) beans can
> take the same id. My solution is a query (to the database) to obtain the
> next value for the primary key. For example, in Oracle, something like
> SEQ_XXX.NEXTVAL. To do this, I propose the use of Stateless Session Bean
> (specific to each Database) which will take the next value with a query to
> database. If you change your database, your only must change this Stateless
> Session Bean.
>
> For example, you have something like that:
> public class DataBaseSpecificLikeOracleBean implements SessionBean {
> public int nextPrimaryKey(String table) {
> String query1 =
> ctx.lookup("java:comp/env/SQLNextValFirstPart"); // For example
> SELECT SEQ_
> String query2 =
> ctx.lookup("java:comp/env/SQLNextValSecondPart"); // For example FROM DUAL
>
> query = query1 + table + query2;
> // Execute the query and return the result
> }
> }
>
> In your Entity Bean:
>
> public class CustomerEntityBean implements EntityBean {
> // Instead of getEJBHome().findNewest() use..
> DataBaseSpecific dbs = ctx.lookup("EJBDataBaseSpecific");
> nextKey = dbs.nextPrimaryKey(0
> protected long getNextKey() {
> long nextKey = 0;
>
> Customer newestCustomer = ((CustomerHome)
> entityContext.getEJBHome()).findNewest();
> // the implementation of findNewest is not shown,
> // i guess the findNewest returns the bean with the highest
> id/primary key
> // in my point of view this is like select max(id) from
> customer + 1
> nextKey = ((CustomerKey)newestCustomer.getPrimaryKey()).key
> + 1;
> return nextKey;
> }
> }
>
>
> And you need, in your JNDI the two parts of a query to obtain next value.
> You can use another DataBaseSpecificBean (for other databses) with the same
> interface and put it instead of this implementation.
> This is not a final solution, only an idea... please, think about it and
> rebuild it!
>
> Regards.
>
> Luis Canals.
>
>
> -----Original Message-----
> From: Jerson Chua [mailto:[EMAIL PROTECTED]]
> Sent: viernes, 08 de septiembre de 2000 9:39
> To: [EMAIL PROTECTED]
> Subject: Generating ID???
>
>
> Hello Guys...
>
> I've read an IBM article and it has an example in generating id/primary key.
> I have a
> doubt that 1 or more bean can get the same id. I want to verify this doubt.
> Is this
> scenario possible?
>
> 1. Customerbean1 retrieves max id
> 2. Customerbean2 retrieves max id
> 3. Customerbean1 increments maxid and store to db
> 4. Customerbean2 increments maxid and store to db
>
> public class CustomerEntityBean {
> public void ejbCreate(String name, int type) {
> key = getNextKey();
> ...
> }
>
> protected long getNextKey() {
> long nextKey = 0;
>
> Customer newestCustomer = ((CustomerHome)
> entityContext.getEJBHome()).findNewest();
> // the implementation of findNewest is not shown,
> // i guess the findNewest returns the bean with the highest
> id/primary key
> // in my point of view this is like select max(id) from
> customer + 1
> nextKey = ((CustomerKey)newestCustomer.getPrimaryKey()).key
> + 1;
> return nextKey;
> }
> }
>
> What's your opinion? Will this design work?
>
> Jerson
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Mail - Free email you can access from anywhere!
> http://mail.yahoo.com/
>
> ===========================================================================
> 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".
>
> This message and any files transmitted with it are confidential and intended
> solely for the use of the individual or entity to whom they are addressed.
> No confidentiality or privilege is waived or lost by any wrong transmission.
> If you have received this message in error, please immediately destroy it
> and kindly notify the sender by reply email.
> You must not, directly or indirectly, use, disclose, distribute, print, or
> copy any part of this message if you are not the intended recipient.
> Opinions, conclusions and other information in this message that do not
> relate to the official business of Newknow shall be understood as neither
> given nor endorsed by it.
>
> ===========================================================================
> 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".
>
__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/
===========================================================================
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".