把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">
<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
-------------------------------------------------------------
不知为什么会这样不解
这个就是延迟加载的问题啦。。。
[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(),加载延迟数据。
去掉延迟加载呢?
或者是你在service里调用一次getWorkFlow()看看有没有被实例化。
如果你在service里调用时被实例化了。那就那样调用一次放那,应该就可以了