IT WORKS!
Here is the complete code:
ejb-jar.xml
<entity>
<display-name>EmployeeEJB</display-name>
<ejb-name>EmployeeEJB</ejb-name>
<local-home>employee.ejb.com.sbm.cts.EmployeeHome</local-home>
<local>employee.ejb.com.sbm.cts.Employee</local>
<ejb-class>employee.ejb.com.sbm.cts.EmployeeBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>EmployeeSchema</abstract-schema-name>
<cmp-field><field-name>firstname</field-name></cmp-field>
<cmp-field><field-name>lastname</field-name></cmp-field>
<cmp-field><field-name>telephone</field-name></cmp-field>
<cmp-field><field-name>employeeid</field-name></cmp-field>
<primkey-field>employeeid</primkey-field>
<resource-ref>
<res-ref-name>jdbc/ctsDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</entity>
jbosscmp-jdbc.xml
<entity>
<ejb-name>EmployeeEJB</ejb-name>
<table-name>employee</table-name>
<cmp-field>
<field-name>firstname</field-name>
<column-name>firstname</column-name>
</cmp-field>
<cmp-field>
<field-name>lastname</field-name>
<column-name>lastname</column-name>
</cmp-field>
<cmp-field>
<field-name>telephone</field-name>
<column-name>telephone</column-name>
</cmp-field>
<cmp-field>
<field-name>employeeid</field-name>
<column-name>employeeid</column-name>
<auto-increment/>
<not-null/>
</cmp-field>
<entity-command name="mysql-get-generated-keys"
class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand"/>
</entity>
code:
// HOME methods
public Integer ejbCreate(EmployeeDetails employeeDetails) throws CreateException {
logger.debug("ejbCreate");
try {
BeanUtils.copyProperties(this, employeeDetails);
} catch (java.lang.reflect.InvocationTargetException e) {
//nothing to log. It's expected because the primary key can't be
// changed.
logger.error("error in invocation" + e.getMessage());
} catch (Exception e) {
logger.error(e.getMessage());
}
return null;
}
public void ejbPostCreate(EmployeeDetails employeeDetails) {
logger.debug("ejbPostCreate");
}
// CMP field accessors
public abstract
String getFirstname();
public abstract void setFirstname(String firstname);
public abstract String getLastname();
public abstract void setLastname(String lastname);
public abstract String getTelephone();
public abstract void setTelephone(String telephone);
public abstract Integer getEmployeeid();
public abstract void setEmployeeid(Integer employeeid);
sql code:
CREATE TABLE employee
(
firstname VARCHAR(30),
lastname VARCHAR(30),
telephone VARCHAR(30),
employeeid int(4) auto_increment,
CONSTRAINT pk_user PRIMARY KEY (employeeid)
);
Thanks everyone.
- walker