You'd need to create a PrimaryKeyBean like mentioned in earlier posts today
only with fields that store the last number issued for each of your other
beans that need these ids.  Then create one instance of that PrimaryKeyBean
to do the work.  Then in the ejbCreate() method, call some findBy on
PrimaryKeyHome to get the PrimaryKey remote interface for that instance, and
call a method on the remote interface that returns the next id for the bean
that is to be created. Like:

public Long ejbCreate() throws RemoteException, CreateException{
                
        PrimaryKey pk=null;
        PrimaryKeyHome
pkhome=(PrimaryKeyHome)getHome("primaryKey/PrimaryKey",PrimaryKeyHome.class)
;
                                
        try{
                pk=pkhome.findByPrimaryKey(new Integer(0));
        }
        catch(Exception e){
                pk=pkhome.create();
        } 
        cancelled=false;
        reservationID=pk.getReservationID();
        return null;
                
}





-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Richard
Kasperowski
Sent: Thursday, June 14, 2001 4:04 PM
To: jboss-user
Subject: [JBoss-user] Auto-increment CMP primary key?


Another newbie question:

Using a totally out-of-the-box JBoss+TomCat, I built a container managed 
EJB.  The EJB's primary key is a Long; the idea is that a simple serial 
number is sufficient.  In my bean's ejbCreate(), is there a recommended 
way to automatically generate the next Long?

Thanks,

-- 
Richard Kasperowski (mailto:[EMAIL PROTECTED])
Tel: 617-576-1552, Fax: 617-576-2441
http://www.altisimo.com/


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to