two ways of doing this...
1. map your ejb pk to another ejb. The counter.jar does this. It creates a long for every "beantype". See the faq at I think there is something under, also. In your ejbCreate(), get a reference to the counter.jar, and then ask for the new pk :
  long id = com.evermind.ejb.CounterUtils.getNextID("java:comp/env/ejb/Counter", "mybeanname");
2. See the chain of articles by Brett McGlaughlin at Instead of using an ejb to generate your pk references, use jdbc and a stateless session bean. In the end you do the same thing in your ejbCreate():
 long id = slsbRemote.getNextID("mybeanname");
And whatever you do, stay away from triggers.
the elephantwalker
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Sergei Batiuk
Sent: Monday, May 14, 2001 10:08 AM
To: Orion-Interest
Subject: Generating primary keys

Hi mailing list,
I have the following problem: the primary key for my EJB is generated at the database level ( a trigger ), so I don't want to generate it in the ejbCreate() method. However, EJB specification says, that the use of the primary key is a MUST. Does anyone have the solution for this problem?
Any help is greatly appreciated.

Reply via email to