Losing object references passed by EJB?
ashman Mar 6, 2012 8:28 AMHi,
I am experiencing a problem, and was hoping someone could set me on the right path!
I have two stateless EJBs CompanySessionBean and ObjectBrokerSessionBean. There is a method getCompanyStatusList in CompanySessionBean which in turn calls a method findAll on the ObjectBrokerSessionBean.
This all seems to work fine. The return from the findAll is a collection of objects (populated with values from the database. Again, this works fine and I have checked that the collection contains 5 populated objects (as expected).
The problem is that when the findAll method returns to the calling getCompanyStatusList method, the collection has 5 empty objects inside.
So maybe the reference to the objects in the collection has been lost somewhere?
I am using AS 7.1.0, and the EJB3.1.
public abstract class BusinessObject
{
public void populate(ResultSet rs)
{
...
...
}
}
}
public abstract class BusinessCodeObject extends BusinessObject
{
public void popultae(ResultSet rs)
{
super.populate(rs);
}
public class CompanyStatus extends BusinessCodeObject implements Serializable
{
public static final String CREATED = "CREATED";
public static final String ACTIVE = "ACTIVE";
public static final String INACTIVE = "INACTIVE";
public static final String ONHOLD = "ONHOLD";
public static final String SELLOFF = "SELLOFF";
public static final String PROSPECTIVE = "PRSPCTV";
}
@Stateless(name = "CompanySession")
@Remote(IMaintainCompany.class)
public class CompanySessionBean extends AbstractSessionBean implements IMaintainCompany {
@Resource
private SessionContext mySessionCtx;
@EJB
IObjectBroker brkr;
public Collection getCompanyStatusList() {
Collection c = brkr.findAll(CompanyStatus.class);
return c; // PROBLEM: c is a collection objects with nulls, rather than the populated values
}
}
@Stateless(name = "ObjectBrokerSession")
@Remote(IObjectBroker.class)
public class ObjectBrokerSessionBean implements IObjectBroker {
@Resource
private SessionContext mySessionCtx;
public Collection findAll(Class clazz) {
Collection ret = new ArrayList();
Connection c = null;
ResultSet rs = null;
CallableStatement cs = null;
c = DatabaseConnectionFactory.getConnection(DATASOURCE);
String sql = "call da_company_status.SEL_ALL (?)"
cs = c.prepareCall(sql);
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.execute();
rs = (ResultSet) cs.getObject(1);
BusinessObject bo;
while (rs.next()) {
bo = (BusinessObject) clazz.newInstance();
bo.populate(rs);
ret.add(bo);
}
return ret; // ret is a collection with objects containing values populated from the database
}