Error checking if entity exists
mhansen Oct 25, 2002 8:09 PMHi
I have a problem with a CMP bean. The problem occurs with both postgresql and mysql so I guess I'm missing something in my configuration. I have a BMP bean up an running already so the database system is running fine. The problem occurs when I call the create method on my home interface. This is how the stack trace looks like:
02:49:20,095 INFO [STDOUT] CustomerBean.setEntityContext(EntityContext) called.
02:49:20,095 INFO [STDOUT] CustomerBean.ejbCreate(String,String) called.
02:49:20,096 INFO [STDOUT] SSN has been set
02:49:20,096 INFO [STDOUT] Name has been set
02:49:20,098 ERROR [Customer] Error checking if entity exists
java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax near '' at line 1
at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
at com.mysql.jdbc.Connection.execSQL(Unknown Source)
at com.mysql.jdbc.PreparedStatement.executeQuery(Unknown Source)
at org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.executeQuery(LocalPreparedStatement.java:289)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.entityExists(JDBCCreateEntityCommand.java:154)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.java:127)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:527)
at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:253)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:270)
at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:731)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
My code looks like this (only parts of it is included):
### ejb-jar.xml ###
<ejb-name>Customer</ejb-name>
CustomerHome
Customer
<ejb-class>CustomerBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Customer</abstract-schema-name>
<cmp-field>
<field-name>sSN</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<primary-field>sSN</primary-field>
<assembly-descriptor>
<container-transaction>
<ejb-name>Customer</ejb-name>
<method-name>*</method-name>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
### jboss.xml ###
<ejb-name>Customer</ejb-name>
<jndi-name>CustomerHome</jndi-name>
### jbosscmp-jdbc.xml ###
java:/MySqlDS
<datasource-mapping>mySQL</datasource-mapping>
<enterprise-beans>
<ejb-name>Customer</ejb-name>
<table-name>customers</table-name>
<cmp-field>
<field-name>sSN</field-name>
<column-name>ssn</column-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
<column-name>name</column-name>
</cmp-field>
</enterprise-beans>
### Customer.java ####
public interface Customer extends EJBObject {
public String getSSN() throws RemoteException;
public void setSSN(String ssn) throws RemoteException;
public String getName() throws RemoteException;
public void setName(String name) throws RemoteException;
}
### CustomerHome.java ###
public interface CustomerHome extends EJBHome {
Customer create(String ssn, String name) throws CreateException, RemoteException;
public Customer findByPrimaryKey(String key) throws FinderException, RemoteException;
}
### CustomerBean.java ###
public abstract class CustomerBean implements EntityBean {
protected EntityContext ctx;
public CustomerBean() {
System.out.println("New customer created.");
}
//
// Getter/setter methods on Entity Bean fields
//
public abstract String getSSN();
public abstract void setSSN(String ssn);
public abstract String getName();
public abstract void setName(String name);
//
// EJB-required methods
//
public void ejbActivate() {
System.out.println("CustomerBean.ejbActivate() called.");
}
public void ejbRemove() throws RemoveException {
System.out.println("CustomerBean.ejbRemove() called.");
}
public void ejbPassivate() {
System.out.println("CustomerBean.ejbPassivate() called.");
}
public void ejbLoad() {
System.out.println("CustomerBean.ejbLoad() called.");
}
public void ejbStore() {
System.out.println("CustomerBean.ejbStore() called.");
}
public void setEntityContext(EntityContext ctx) {
System.out.println("CustomerBean.setEntityContext(EntityContext) called.");
this.ctx = ctx;
}
public void unsetEntityContext() {
System.out.println("CustomerBean.unsetEntityContext() called.");
this.ctx = null;
}
public String ejbCreate(String ssn, String name) throws CreateException {
System.out.println("CustomerBean.ejbCreate(String,String) called.");
setSSN(ssn);
System.out.println("SSN has been set");
setName(name);
System.out.println("Name has been set");
return ssn;
}
public void ejbPostCreate(String ssn, String name) {
System.out.println("CustomerBean.ejbPostCreate(String,String) called.");
}
}
Any help would be appreciated