-
1. Re: Automatic generation of primary key
lafr May 31, 2006 4:35 PM (in response to iraten)Look for auto-increment and entity-command.
-
2. Re: Automatic generation of primary key
iraten Jun 1, 2006 4:20 AM (in response to iraten)Thank you for your answer.
It was the way I found.
I use<entity-command name="key-generator" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCKeyGeneratorCreateCommand"> <attribute name="key-generator-factory"> HiLoKeyGeneratorFactory </attribute> </entity-command>
Unfortunatly, I get a ClassCastException because it generates a Long and I need an Integer.
Do you now the name of an appropriate factory?
Thank you -
3. Re: Automatic generation of primary key
lauri Jun 1, 2006 11:18 AM (in response to iraten)Do you use xdoclet for .xml generation?
I do, so for pk of Integer my attributes are:
class level/** @jboss.entity-command name="mysql-get-generated-keys" @ejb.bean primkey-field="id" ... also other settings */ class ....
method level/** * @ejb.pk-field * @jboss.persistance auto-increment="true" */ public abstract Integer getId();
This results in
jbosscmp-jdbc-xml<entity> <ejb-name>MyEJB</ejb-name> <cmp-field> <field-name>id</field-name> <autoincrement/> ..... </cmp-field> .... <entity-command name="mysql-get-generated-keys"></entity-command> </entity>
ejb-jar.xml is common. -
4. Re: Automatic generation of primary key
lauri Jun 1, 2006 11:19 AM (in response to iraten)Answer related to mysql indeed.
But there is similar support for other common databases . -
5. Re: Automatic generation of primary key
iraten Jun 2, 2006 4:46 AM (in response to iraten)Thank you for your reply.
I've tried your solution using<entity-command name="mysql-get-generated-keys"></entity-command>
and<autoincrement/>
Unfortunatly, it doesn't solve my problem (I still get a null primary key).
Did you do something else in order to find this class?(maybe adding a jar or a reference to a jar....)?
Thank you again -
6. Re: Automatic generation of primary key
lauri Jun 2, 2006 9:16 AM (in response to iraten)I don't know what it could be then :(.
As far as i understand, general idea of pk generation is to tell EJB engine what type (class) of pk it will be, and tell details to jboss personally.
Something about integer type should be mentioned in ejb-jar.xml and particular instructions in jbosscmp-jdbc.xml
How your ejbCreate and ejbPostCreate looks like?
It should not contain pk field in signature and no calls to pk inside i mean nothing of
getId() (could be not assigned yet)
and
setId(id) will override autoincremented value.
That is just my current understanding, it works for me.