Hello,
I am having trouble getting JBoss to create primary keys with the UUIDKeyGeneratorFactory (I tried with MySQL generate keys with no luck also). I get the following exception when I try to create a new Share bean:
javax.ejb.CreateException: Could not create entity:java.sql.SQLException: Column 'id' cannot be null at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:327)
If I explictly call the setId() method in ejbCreate everything works fine and row is inserted in my table... any help would be much appreciated. I have included relevant files below:
ShareBean.java
package tutorial.ejb;
import java.rmi.RemoteException;
import java.util.Date;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
/**
* @ejb.bean name="Share"
* display-name="Name for Share"
* description="Description for Share"
* local-jndi-name = "ejb/ShareLocal"
* cmp-version="2.x"
* view-type="local"
* primkey-field="id"
* schema="shares"
*
* @jboss.persistence datasource = "java:/MySqlDS"
* @jboss.persistence datasource-mapping = "mySQL"
* @jboss.persistence create-table = "true"
* @jboss.persistence remove-table = "true"
*
* @ejb.finder query="SELECT OBJECT(o) FROM shares as o"
* signature="java.util.Collection findAll()"
*
* @jboss.unknown-pk class="String" column-name = "id" jdbc-type = "String" sql-type = "VARCHAR"
* @jboss.entity-command name="key-generator" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCKeyGeneratorCreateCommand"
* @jboss.entity-command-attribute name = "key-generator-factory" value = "UUIDKeyGeneratorFactory"
*/
public abstract class ShareBean implements EntityBean {
public ShareBean() {
super();
// TODO Auto-generated constructor stub
}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbLoad() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbRemove() throws RemoveException, EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbStore() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void setEntityContext(EntityContext ctx)
throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
public void unsetEntityContext() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/**
* Create method
* @ejb.create-method view-type = "local"
*/
public String ejbCreate(String symbol, Date date, Integer quantity, Double price, Double commission) throws javax.ejb.CreateException {
// TODO Auto-generated method stub
setSymbol(symbol);
setDate(date);
setQuantity(quantity);
setPrice(price);
setCommission(commission);
return null;
}
/**
* Post Create method
*/
public void ejbPostCreate(String symbol, Date date, Integer quantity, Double price, Double commission) throws javax.ejb.CreateException {
// TODO Auto-generated method stub
}
/**
* Getter for CMP Field id
*
* @ejb.pk-field
* @ejb.persistence column-name = "id"
* @ejb.persistent-field
* @ejb.interface-method view-type="local"
*/
public abstract String getId();
/**
* Setter for CMP Field id
*
* @ejb.interface-method view-type="local"
*/
public abstract void setId(String value);
/**
* Getter for CMP Field symbol
*
*
* @ejb.persistent-field
* @ejb.interface-method view-type="local"
*/
public abstract String getSymbol();
/**
* Setter for CMP Field symbol
*
* @ejb.interface-method view-type="local"
*/
public abstract void setSymbol(String value);
/**
* Getter for CMP Field date
*
*
* @ejb.persistent-field
* @ejb.interface-method view-type="local"
*/
public abstract java.util.Date getDate();
/**
* Setter for CMP Field date
*
* @ejb.interface-method view-type="local"
*/
public abstract void setDate(java.util.Date value);
/**
* Getter for CMP Field quantity
*
*
* @ejb.persistent-field
* @ejb.interface-method view-type="local"
*/
public abstract java.lang.Integer getQuantity();
/**
* Setter for CMP Field quantity
*
* @ejb.interface-method view-type="local"
*/
public abstract void setQuantity(java.lang.Integer value);
/**
* Getter for CMP Field price
*
*
* @ejb.persistent-field
* @ejb.interface-method view-type="local"
*/
public abstract java.lang.Double getPrice();
/**
* Setter for CMP Field price
*
* @ejb.interface-method view-type="local"
*/
public abstract void setPrice(java.lang.Double value);
/**
* Getter for CMP Field commission
*
*
* @ejb.persistent-field
* @ejb.interface-method view-type="local"
*/
public abstract java.lang.Double getCommission();
/**
* Setter for CMP Field commission
*
* @ejb.interface-method view-type="local"
*/
public abstract void setCommission(java.lang.Double value);
}
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar >
<description><![CDATA[No Description.]]></description>
<display-name>Generated by XDoclet</display-name>
<enterprise-beans>
<!-- Session Beans -->
<session >
<description><![CDATA[Description for Fibo]]></description>
<display-name>Name for Fibo</display-name>
<ejb-name>Fibo</ejb-name>
<home>tutorial.interfaces.FiboHome</home>
<remote>tutorial.interfaces.Fibo</remote>
<ejb-class>tutorial.ejb.FiboBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<!--
To add session beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called session-beans.xml that contains
the <session></session> markup for those beans.
-->
<!-- Entity Beans -->
<entity >
<description><![CDATA[Description for Share]]></description>
<display-name>Name for Share</display-name>
<ejb-name>Share</ejb-name>
<local-home>tutorial.interfaces.ShareLocalHome</local-home>
<local>tutorial.interfaces.ShareLocal</local>
<ejb-class>tutorial.ejb.ShareBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>shares</abstract-schema-name>
<cmp-field >
<description><![CDATA[Getter for CMP Field id]]></description>
<field-name>id</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[Getter for CMP Field symbol]]></description>
<field-name>symbol</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[Getter for CMP Field date]]></description>
<field-name>date</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[Getter for CMP Field quantity]]></description>
<field-name>quantity</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[Getter for CMP Field price]]></description>
<field-name>price</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[Getter for CMP Field commission]]></description>
<field-name>commission</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<query>
<query-method>
<method-name>findAll</method-name>
<method-params>
</method-params>
</query-method>
<ejb-ql><![CDATA[SELECT OBJECT(o) FROM shares as o]]></ejb-ql>
</query>
<!-- Write a file named ejb-finders-ShareBean.xml if you want to define extra finders. -->
</entity>
<!--
To add entity beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called entity-beans.xml that contains
the <entity></entity> markup for those beans.
-->
<!-- Message Driven Beans -->
<!--
To add message driven beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called message-driven-beans.xml that contains
the <message-driven></message-driven> markup for those beans.
-->
</enterprise-beans>
<!-- Relationships -->
<!-- Assembly Descriptor -->
<assembly-descriptor >
<!--
To add additional assembly descriptor info here, add a file to your
XDoclet merge directory called assembly-descriptor.xml that contains
the <assembly-descriptor></assembly-descriptor> markup.
-->
<!-- finder permissions -->
<!-- finder permissions -->
<!-- transactions -->
<!-- finder transactions -->
</assembly-descriptor>
</ejb-jar>
jbosscmp-jdbc.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">
<jbosscmp-jdbc>
<defaults>
</defaults>
<enterprise-beans>
<!--
To add beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called jbosscmp-jdbc-beans.xml
that contains the <entity></entity> markup for those beans.
-->
<entity>
<ejb-name>Share</ejb-name>
<datasource>java:/MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
<create-table>true</create-table>
<remove-table>true</remove-table>
<cmp-field>
<field-name>id</field-name>
<column-name>id</column-name>
</cmp-field>
<cmp-field>
<field-name>symbol</field-name>
</cmp-field>
<cmp-field>
<field-name>date</field-name>
</cmp-field>
<cmp-field>
<field-name>quantity</field-name>
</cmp-field>
<cmp-field>
<field-name>price</field-name>
</cmp-field>
<cmp-field>
<field-name>commission</field-name>
</cmp-field>
<unknown-pk>
<unknown-pk-class>String</unknown-pk-class>
<column-name>id</column-name>
<jdbc-type>String</jdbc-type>
<sql-type>VARCHAR</sql-type>
</unknown-pk>
<entity-command name="key-generator" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCKeyGeneratorCreateCommand">
<attribute name="key-generator-factory">UUIDKeyGeneratorFactory</attribute>
</entity-command>
<!-- jboss 3.2 features -->
<!-- optimistic locking does not express the exclusions needed -->
</entity>
</enterprise-beans>
</jbosscmp-jdbc>