CMP:auto-pk-increment problem with PostgreSQL
mandarjboss Mar 2, 2004 11:45 PMI am trying to implement auto-increment of primary key feature of JBoss3.2.
I am giving following code and allowing JBoss to auto-create the tables.
But i am still getting the exception as,
java.sql.SQLException: ERROR: ExecInsert: Fail to add null value in not null attribute id
/*
* Created on 25-feb-2004
*
*/
package questionbank.ejb;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
/**
*
* @ejb.bean
* cmp-version = "2.x"
* jndi-name = "CustomerBean"
* name = "Customer"
* primkey-field = "id"
* schema = "CustomerSchema"
* type = "CMP"
* view-type = "remote"
*
* @ejb.home remote-class = "ejb.CustomerHome"
* @ejb.interface remote-class = "ejb.Customer"
*
* @ejb.persistence
* table-name = "Customer"
*
* @jboss.entity-command
* name = "postgresql-fetch-seq"
*
*
*/
public abstract class CustomerBean implements EntityBean {
/**
* @param email
* @param password
* @param lastname
* @param firstname
* @return
* @throws CreateException
*
* @ejb.create-method
*/
public Integer ejbCreate(String email, String pwd,String lastname, String firstname) throws CreateException {
setEmail(email);
setPassword(password);
setLastname(lastname);
setFirstname(firstname);
return null;
}
/**
* @throws CreateException
*/
public void ejbPostCreate(String email, String password, String lastname, String firstname) throws CreateException {
}
/**
* @return
*
* @ejb.interface-method
* @ejb.pk-field
* @ejb.persistence
* column-name = "id"
* sql-type = "INT"
* @jboss.persistence
* auto-increment = "true"
*/
public abstract Integer getId();
/**
* @param id
*/
public abstract void setId(Integer id);
/**
* @return
*
* @ejb.interface-method
* @ejb.persistence
* column-name = "email"
* sql-type = "varchar"
* @ejb.persistent-field
*/
public abstract String getEmail();
/**
* @param email
*
* @ejb.interface-method
*/
public abstract void setEmail(String email);
/**
* @return
*
* @ejb.interface-method
* @ejb.persistence
* column-name = "password"
* sql-type = "varchar"
* @ejb.persistent-field
*/
public abstract String getPassword();
/**
* @param password
*
* @ejb.interface-method
*/
public abstract void setPassword(String password);
/**
* @return
*
* @ejb.interface-method
* @ejb.persistence
* column-name = "lastname"
* sql-type = "varchar"
* @ejb.persistent-field
*/
public abstract String getLastname();
/**
* @param lastname
*
* @ejb.interface-method
*/
public abstract void setLastname(String lastname);
/**
* @return
*
* @ejb.interface-methodB
* column-name = "firstname"
* sql-type = "varchar"
* @ejb.persistent-field
*/
public abstract String getFirstname();
/**
* @param firstname
*
* @ejb.interface-method
*/
public abstract void setFirstname(String firstname);
}
In my standardjbosscmp-jdbc.xml i have the following,
<entity-command name="postgresql-fetch-seq" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCPostgreSQLCreateCommand">
</entity-command>