Hi,
I'm trying to develope a CMP entity bean under jboss with mysql db.
My entity bean must have an autoincrement primary key.
The following is part of my: standardjbosscmp-jdbc.xml
<unknown-pk>
<key-generator-factory>UUIDKeyGeneratorFactory</key-generator-
factory>
<unknown-pk-class>java.lang.Object</unknown-pk-class>
<field-name>id</field-name>
<column-name>id</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INT(11)</sql-type>
<auto-increment/>
</unknown-pk>
<entity-command name="default"/>
I have deployed my entity bean without problems and the following
is my deployment descriptor:
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>fisrtEJB</ejb-name>
<home>my.java.test.FirstHomeRemote</home>
<remote>my.java.test.FirstRemote</remote>
<ejb-class>my.java.test.FirstBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Object</prim-key-class>
<reentrant>False</reentrant>
<abstract-schema-name>MySchema</abstract-schema-name>
<cmp-field><field-name>name</field-name></cmp-field>
<cmp-field><field-name>surname</field-name></cmp-field>
<cmp-field><field-name>mobile</field-name></cmp-field>
<security-identity><use-caller-identity/></security-identity>
</entity>
</enterprise-beans>
<assembly-descriptor>
....
etc
NB: I don't specify cmp id field! It is correct?
When I have deployed entity bean the created table have
id,name,surname and mobile fields
interface:
public interface FirstHomeRemote extends javax.ejb.EJBHome{
public FirstRemote create() throws CreateException, RemoteException;
public FirstRemote findByPrimaryKey(Object pk) throws
FinderException, RemoteException;
}
FirstBean:
public Object ejbCreate()throws CreateException{
return null;
}
public void ejbPostCreate(){
}
In this class I don't have implemented cmp field id.
The FirstRemote class contains abstract method: setName(),getName()
etc...
Now let's see the client:
Context jndiContext = getInitialContext(); // get jnp://localhost:
1099 etc..
Object ref = jndiContext.lookup("FirstEJB");
FirstHomeRemote home = (FirstHomeRemote)
****tableRemoteObject.narrow(ref,FirstHomeRemote.class);
FirstRemote myfirst = (FirstRemote)home.create();
myfirst.setName("John");
the statement: FirstRemote myfirst = (FirstRemote)home.create();
return exception: javax.ejb.CreateException: Primary key for
created instance is null.
Within created table I see that id (autoincrement primary key)
is added and Jboss server.log don't return errors, so I can't
figure
It out this problems..
please help me.
Teo


|