yangsheng0915 2009-01-13 16:08
浏览 287
已采纳

把xfire整合到spring+hibernate框中当查询一个对像时报空指针异常

问题如下:

接口

public interface FlowService {




    // 查询已发布的流程并且已添加了表单模板

public List findReleaseFlowAndTemp(Map filter);

}

---------------------------------------------------------------------------

在接口FlowService的同一文件文件夹下增加了FlowService.aegis.xml文件内容如下



<mappings>

    <mapping>

        <method name="findReleaseFlowAndTemp">

            <parameter index="0" componenttype="java.lang.String">

            <return-type componenttype="com.acms.demon.workflow.model.ReleaseFlow">

        </method>

    </mapping>

</mappings>

------------------------------------------------------------------------------

该接口有一方法返加一个List集合里面存放ReleaseFlow对像,这个对像中有一个自定义的WorkFlow对像,

在ReleaseFlow对像的同一文件夹下增加了

ReleaseFlow.aegis.xml文件内容如下

  

<mappings xmlns:my="http://com.acms.demon.workflow"&gt;  

  <mapping name="my:ReleaseFlow">  

    <property name="workFlow" ignore="true">

  </mapping>  

</mappings>

----------------------------------------------------------------------

实现类

public class FlowServiceImpl  implements FlowService{

private WorkflowDAO workFlowDAO;




public WorkflowDAO getWorkFlowDAO() {

return workFlowDAO;

}

public void setWorkFlowDAO(WorkflowDAO workFlowDAO) {

this.workFlowDAO = workFlowDAO;

}

public List findReleaseFlowAndTemp(Map filter) {




return workFlowDAO.findReleaseFlowAndTemp(filter);

}

-----------------------------------------------------------------------

能正常生成wsdl文件

在客户端测式findReleaseFlowAndTemp方法时能从数据查询到一个结果集返加给我这个方法.但是当从结果集中取出WorkFlow对像的一个属性进报空指针异常

ReleaseFlow rf=(ReleaseFlow)resultList.get(i);

rf.getWorkFlow().getProcessDefinitionName()这行是取出releaseFlow对像的属性Workflow对像的一个属性时报空指针异常,取其它值正常。



请各位帮忙看下如何解决谢谢!


问题补充:
现在的问题是:

rf.getWorkFlow() == null



是不是延迟加载的问题?



你可以参考一下这篇文章:

http://chengyao.iteye.com/blog/85622



感谢你的回复我就是参照这篇文章做的应该是延迟加载的问题,可能是没有加载但是不知如何解决
问题补充:
回复:汪兆铭



谢谢你的回复,我现在去掉了<property name="workFlow" ignore="true"> 也就是WorkFlow也被序列化,如果不去掉改其它地方也是rf.getWorkFlow() == null 。

---------------------------------------------------

同时在接口中增加以下方法

public ReleaseFlow findReleaseFlowById(String rid);

---------------------------------------------------



实现类的方法

public ReleaseFlow findReleaseFlowById(String rid) {

ReleaseFlow rf= workFlowDAO.findReleaseFlowById(rid);

System.out.println("WorkFlow实例化对像: "+rf.getWorkFlow());

return rf;

}

------------------------------------------------------

现在在客户端访问webservcie时可以通过

rf.getWorkFlow().getProcessDefinitionName()取到值,实现类的System.out.println("WorkFlow实例化对像: "+rf.getWorkFlow());

这行代码也能打印出对workflow对像已经实列化,但是如果去掉rf.getWorkFlow()方法在客户端rf.getWorkFlow()会抛空指针异常

-------------------------------------------------------

Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: could not initialize proxy - the owning Session was closed

org.codehaus.xfire.fault.XFireFault: could not initialize proxy - the owning Session was closed

-------------------------------------------------------------

不知为什么会这样不解



  • 写回答

3条回答 默认 最新

  • Candyut 2009-01-14 15:18
    关注

    这个就是延迟加载的问题啦。。。
    [quote]
    Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: could not initialize proxy - the owning [color=red]Session was closed[/color]
    org.codehaus.xfire.fault.XFireFault: could not initialize proxy - the owning [color=red]Session was closed[/color]
    [/quote]

    当你的客户端已经取得到ReleaseFlow的时候,这个时候你服务端的Session已经关闭了。
    要么你选择不对该字段使用延迟加载,要么就是自己编码在Session未结束之前(也就是你的Service方法执行完之前),显示的调用getWorkFlow(),加载延迟数据。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿