I tried with DB (MySQL) sequence in EJB2.0. I have the following problems.
The column/field (orderID) using the sequence is primary key. My code is
like this:

 public abstract class OrderRequestBean implements EntityBean {
//........

  public java.lang.Integer ejbCreate(java.lang.String userid, String
orderInfo) throws CreateException {
    setOrderID(new Integer(0));
/*
orderID uses sequence feature in MySQL. But as the primary key, it has to be
set a non-null
value in ejbCreate method.  This is the 1st problem.
                                            ^^^^^^^^^^^^^^^^
For MySQL, you can set 0, and it will generate the next sequence
number and replace 0.
*/
    setUserid(userid);
    setOrderInfo(orderInfo);

    return null;
  }
//.....
}


public class OrderControllerBean implements SessionBean {
//..............
  public int processOrder(Order order) {
//..............
    try {
      Object ref = ctx.lookup("OrderRequest");
      String user = "alvin";
      OrderRequestHome orderRequestHome =
(OrderRequestHome )PortableRemoteObject.narrow(ref, OrderRequestHome
.class);
      OrderRequest orderRequestHome = rqHome.create(user, starttime,
orderInfo);
      return orderRequest.getOrderID().intValue();
/*
It will return 0!! Not the real sequence number created in DB. So how can I
get the
orderID and return to the client? This is the 2nd problem.
                                                  ^^^^^^^^^^^^^^^^^
*/
    } catch (Exception e) {
      e.printStackTrace();
   }
  }
//..................
}

Any comments?



> Delivered-To: [EMAIL PROTECTED]
> Date:         Tue, 19 Mar 2002 10:33:45 -0800
> Reply-To: Gene Chuang <[EMAIL PROTECTED]>
> Sender: A mailing list for Enterprise JavaBeans development
> <[EMAIL PROTECTED]>
> From: Gene Chuang <[EMAIL PROTECTED]>
> Subject:      Re: High performance synchronized counter?
> To: [EMAIL PROTECTED]
>
>
> Try db sequence?  You'll find your counter worthless the moment you
upgrade
> your
> enterprise app to a clustered environment.
>
>
> Gene
> --- Alvin Wang <[EMAIL PROTECTED]> wrote:
> > Hi! Gurus,
> >
> > I implemented a synchronized counter (for example Order ID) using Entity
> > bean and use exclusive concurrency control perperty in WL to ganrantee
that
> > only one transacation is reading/writing that bean at one time point, so
> > that the generated order id will not duplicate. However, I found it is a
> > bottleneck. So what is the better design to improve the performance? Or
is
> > there other way to generate non-duplicate ID strings?
> >
> > Thanks!
>
>
>
>

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