ejb中relationship的问题,高手请进

sanyo_rider sanyo_rider 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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?
...全文
评论 6
收藏 已收藏
分享
返回顶部
sanyo_rider
Java EE 67,535 成员 225,843 内容