Or, if your not concerned with humans seeing the data, you could use the 
java.rmi.server.UID class. This class will generate a unique ID, with 
respect to the host its running on. For an ID unique accross a cluster, add 
the IP address to it.

Jim

--On Thursday, June 14, 2001 4:28 PM -0500 "Nordahl, David C" 
<[EMAIL PROTECTED]> wrote:

> 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.cla
> ss) ;
>                               
>       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



********************************************
I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I -
I took the one less traveled by,
And that has made all the difference.

- Robert Frost, 1916


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

Reply via email to