No such Entity!
kkaal Jan 9, 2004 7:37 AMHi, after having manged session-beans, I am feeling like a newbie again!
I am trying to create an CMP bean. When I lookup the home-interface, it is allright. But when I try the "findByPrimaryKey method, it throws an ObjectNotFoundException: Not such entity!
A suitable table exists in the DB.
could you plse have a look at the code?
Thanks
Klaus
-------------------- 8< Client -code --------------------------------------------
public String getEnvString() {
EnvVars ev = null;
Collection cev = null;
try {
Object ref = jndiContext.lookup("sys/env_variables");
EnvVarsHome evh = (EnvVarsHome) javax.rmi.PortableRemoteObject.narrow(ref, EnvVarsHome.class);
ev = evh.findByPrimaryKey(new Integer(1)); //this throws the exception!
return "TEST2";
}
catch (RemoteException e2) {
e2.printStackTrace();
}
catch (FinderException e2) {
e2.printStackTrace();
}
catch (ClassCastException e) {
e.printStackTrace();
}
catch (NamingException e) {
e.printStackTrace();
}
try {
return ev.getName();
}
catch (RemoteException e1) {
e1.printStackTrace();
return "ERR";
}
}
-------------------------------------------------------------------------------
---------------- 8< CMP Bean --------------------------------------------
/**
* @ejb.bean cmp-version = "2.x"
* type = "CMP"
* view-type = "both"
* name = "EnvVars"
* description = "Handles system data"
* jndi-name = "sys/env_variables"
* local-jndi-name = "sys/env_variables_local"
* display-name = "Environment"
* primkey-field = "id"
* schema="envi"
*
* @ejb.persistence
* table-name="environment"
*
* @ejb.pk class = "java.lang.Integer"
*
*
* @ejb.finder
* signature = "EnvVars findByPrimaryKey(java.lang.Integer id)"
* unchecked = "true"
* query = "SELECT OBJECT(a) from envi a where a.id = 1"
* result-type-mapping="Local"
*
* @jboss.entity-command
* name="mysql-get-generated-keys"
* @jboss.persistence
* datasource="MySqlPublDS"
* table-name="environment"
* datasource-mapping = "mySQL"
* create-table = "true"
*
*/
public abstract class EnvVarsBean implements EntityBean {
Integer id;
String name;
public EnvVarsBean() {
super();
}
/**
* @ejb.create-method
*/
public Integer ejbCreate( String nam ) throws CreateException{
this.setName( nam );
return null;
}
public void ejbActivate() throws EJBException, RemoteException {}
public void ejbLoad() throws EJBException, RemoteException {}
public void ejbPassivate() throws EJBException, RemoteException {}
public void ejbRemove() throws RemoveException, EJBException, RemoteException {}
public void ejbStore() throws EJBException, RemoteException {}
public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
public void unsetEntityContext() throws EJBException, RemoteException {}
/**
* @ejb.interface-method
* @ejb.persistence column-name="id"
* @ejb.pk-field
*
* @jboss.column-name name="id"
* @jboss.persistence auto-increment="true"
*/
public abstract Integer getId();
/**
*@ejb.interface-method
*/
public abstract void setId(Integer i);
/**
*@ejb.interface-method
*/
public abstract String getName();
/**
*@ejb.interface-method
*/
public abstract void setName( String nam );
}
------------------------------------------------------------------------------------