How to resolve the "id may not be null"
ipozeng Dec 24, 2001 8:20 PMHi,friends
I am not familiar with EntityBean.Recently i changed a session bean to entity bean as below:
home interface:
...
public interface CoffeesHome extends javax.ejb.EJBHome
{
public Coffees create() throws RemoteException, CreateException;
}
remote interface
...
public interface Coffees extends EJBObject {
public RowSet getCoffees() throws RemoteException, SQLException;
public void updateCoffees(RowSet rs) throws RemoteException, SQLException;
}
entity bean
...
public class CoffeesEJB implements EntityBean
{
private EntityContext ctx = null;
// EJB create method
public Object ejbCreate() throws CreateException
{
return null;
}
public void ejbPostCreate() throws CreateException
{
}
//business method
private Connection getConnection() throws Exception
{
}
public RowSet getCoffees() throws SQLException
{
}
public void updateCoffees(RowSet rs) throws SQLException
{
}
public void setEntityContext(EntityContext ec)
{
this.ctx = ec;
}
public void unsetEntityContext()
{
this.ctx = null;
}
public void ejbRemove() {}
public void ejbPassivate() {}
public void ejbActivate() {}
public void ejbLoad() {}
public void ejbStore() {}
}
ejb-jar.xml
<ejb-name>CoffeesEJB</ejb-name>
example4/CoffeesHome
example4/Coffees
<ejb-class>example4/CoffeesEJB</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
false
<transaction-type>Container</transaction-type>
<assembly-descriptor>
<container-transaction>
<ejb-name>CoffeesEJB</ejb-name>
<method-name>*</method-name>
<trans-attribute>Supports</trans-attribute>
</container-transaction>
</assembly-descriptor>
<resource-ref>
<res-ref-name>jdbc/SQLServerPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
jboss.xml
<ejb-name>CoffeesEJB</ejb-name>
<jndi-name>ejb/Coffees</jndi-name>
<reference-descriptor>
<resource-description>
<res-ref-name>jdbc/SQLServerPool</res-ref-name>
<jndi-name>java:/SQLServerPool</jndi-name>
</resource-description>
</reference-descriptor>
.....
After deploying it,i used a client to test it:
...
Object obj = ctx.lookup("ejb/Coffees");
CoffeesHome coffeesHome = (CoffeesHome)
PortableRemoteObject.narrow(obj, CoffeesHome.class);
System.out.println("got home");
Coffees coffees = coffeesHome.create(); <----report error here
System.out.println("got remote interface");
...
Coffees coffees = coffeesHome.create(); will report "id may not be null"
I am a newbie for entity bean.Please give me some suggestion.
Best Regards!