ejb中relationship的问题,高手请进
1、建立实体BEAN 有两个实体BEAN,DhbDdxgdb、Rybm,关系是多对一。
2、建立session bean 我在sessionbean 中调用他们代码如下:结果没问题
Collection c=null;
//J2eeUser4 userbm=null;
RybmHome rybmhome=null; //HOME
Rybm rybm=null; //LOCAL
DhbDdxgdb dhbddxgdb=null;
try{
Context ctx = new InitialContext();
Object objRef = ctx.lookup("Rybm");
rybmhome = (RybmHome) javax.rmi.PortableRemoteObject.narrow(objRef,
RybmHome.class);
rybm=rybmhome.findByPrimaryKey("xt12");
//out.println(rybm.getRybm());
c=rybm.getDhbDdxgdb();
iter=c.iterator();
/* while (iter.hasNext())
{
dhbddxgdb=(DhbDdxgdb)iter.next();
System.out.println(dhbddxgdb.getDhr());
}*/
}catch (Exception ee)
{
System.out.println("error in sessionbean");
}
////////////////////////////////////////////////////////
3、在客户调用:然后我又到 jsp调用sessionbean 代码如下:
Collection c=null;
Iterator iter=null;
//J2eeUser4 userbm=null;
DhbDdxgdb dhbddxgdb=null;
getmcp7Home rybmhome=null; //HOME
getmcp7 rybm=null; //LOCAL
Context ctx = new InitialContext();
Object objRef = ctx.lookup("getmcp7");
rybmhome = (getmcp7Home) javax.rmi.PortableRemoteObject.narrow(objRef,
getmcp7Home.class);
rybm=rybmhome.create();
//out.println(rybm.getRybm());
iter=rybm.getResult();
//out.println(c.size());
//iter=c.iterator();
while (iter.hasNext())
{
dhbddxgdb=(DhbDdxgdb)iter.next();
out.println(dhbddxgdb.getDhr());
}
//////////////////////////////////////////////////////////////////////
4、出现错误如下:org.apache.jasper.JasperException: The iterator of a CMR collection may only be used within the transction in which it was created
///////////////////////////////////////////
5、问题:我如何解决?是否只能在sessionbean里把所有数据写到数组,然后把数组返回给jsp?