[jboss-user] [EJB/JBoss] - Jboss Mysql unknown primary key
teodoro21
do-not-reply at jboss.com
Wed Feb 14 02:57:10 EST 2007
Hi,
I'm trying to develope a CMP entity bean under jboss with mysql db.
I'd want that my CMP entity bean has 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>
<ejb-name>fisrtEJB</ejb-name>
my.java.test.FirstHomeRemote
my.java.test.FirstRemote
<ejb-class>my.java.test.FirstBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Object</prim-key-class>
False
<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>
</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 methods: 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)
PortableRemoteObject.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 table 'MySchema' I see that id (autoincrement primary key)
is added and Jboss server.log don't return errors but all others fields are empty, so I don't be
able to figure It out this problem.
thanks Teo
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4016230#4016230
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4016230
More information about the jboss-user
mailing list