Look for auto-increment and entity-command.
Thank you for your answer.
It was the way I found.
<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?
Do you use xdoclet for .xml generation?
I do, so for pk of Integer my attributes are:
/** @jboss.entity-command name="mysql-get-generated-keys" @ejb.bean primkey-field="id" ... also other settings */ class ....
/** * @ejb.pk-field * @jboss.persistance auto-increment="true" */ public abstract Integer getId();
This results in
<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.
Answer related to mysql indeed.
But there is similar support for other common databases .
Thank you for your reply.
I've tried your solution using
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
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)
setId(id) will override autoincremented value.
That is just my current understanding, it works for me.