You need to implement two interfaces (in package org.jboss.ejb.plugins.keygenerator) public interface KeyGenerator { public Object generateKey(); }
public interface KeyGeneratorFactory { public String getFactoryName(); public KeyGenerator getKeyGenerator() throws Exception; } Then deploy/bind the factory to JNDI and declare entity-command in jbosscmp-jdbc.xml supplying fractory's JNDI name, for example <!-- uses key generator to fetch the next key value --> <entity-command name="key-generator"> <attribute name="key-generator-factory">UUIDKeyGeneratorFactory</attribute> </entity-command> In ejbCreate container calls KeyGenerator.generateKey() to set PK value. There is UUID key generator in 3.2 and there is HiLo generator (something like you are going to implement with EJBs) in HEAD. If you really would like to go this route, feel free to contact me. BTW, key generation welcomes contributions. In 4.0 it is also used for our JDO implementation JBossDO. If anyone is interested in contribution, please, contact me. alex Thursday, June 26, 2003, 10:15:30 AM, Marco Tedone wrote: MT> Thank you Alex, I have already received a possible solution from Marco MT> Garbelini and I'll try it, but particularly, the one you are suggesting (my MT> own key generator class) sounds interesting. How could I implement it in the MT> EJB CMP architecture? MT> Marco MT> ----- Original Message ----- MT> From: "Alexey Loubyansky" <[EMAIL PROTECTED]> MT> To: "Marco Tedone" <[EMAIL PROTECTED]> MT> Sent: Thursday, June 26, 2003 7:12 AM MT> Subject: Re: [JBoss-user] Question about CMP entity >> Hello Marco, >> >> if the problem really is a primary key generation you could consider >> entity-commands in JBoss-3.2. >> The options are: >> - database key generation (sequences, etc); >> - custom sql; >> - you can supply your own key generator class that will be asked for >> the next key; >> - JDBC3.0 PreparedStatement.getGeneratedKeys(). >> >> alex >> >> Thursday, June 26, 2003, 1:06:43 AM, Marco Tedone wrote: >> >> MT> Sorry guru for the [silly] question: I am having a discussion with MT> people in >> MT> my project regarding the container work with CMP entity beans. More >> MT> specifically, we want to implement a Numerator table to assign numbers MT> to >> MT> several entities of our model. >> >> MT> Suppose a client wants to assign a value to a peopleId field in a MT> People >> MT> table, then it will in order: >> >> MT> 1) Access the Numerator table (behind a CMP entity bean) >> MT> 2) Retrieve the value from the number field; >> MT> 3) Assign that value to peopleId >> MT> 4) Increment the value by 1 >> >> MT> What I am saying to the guys in the project is that the container MT> (Jboss in >> MT> our case) could ensure that, from the moment when the number is MT> retrieved to >> MT> the moment when the number is incremented by 1 nobody else will be MT> able to >> MT> alter the value of the number field in the Numerator table. Someone is >> MT> replying that we should implement a synchronized method. Is that MT> really >> MT> necessary? I'm quite sure that there is a way to instruct the MT> container to >> MT> 'lock' in a certain sense the value of the number field. One way could MT> be a >> MT> transaction (shall we use synchronization in this case?); is there MT> anything >> MT> simplier? >> >> MT> Many thanks for your time, >> >> MT> Marco ------------------------------------------------------- This SF.Net email is sponsored by: INetU Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user