ibatis中使用rowhandler并且在sqlmap中联合查询时出错:UncategorizedSQLException

问题描述

错误信息如下:org.springframework.jdbc.UncategorizedSQLException:SqlMapClientoperation;uncategorizedSQLExceptionforSQL[];SQLstate[null];errorcode[0];---Theerroroccurredincom/citycube/mabole/dao/resume/Resume.ibatis.xml.---Theerroroccurredwhileapplyingaresultmap.---ChecktheResume.getPositionMyFeaturedResume-AutoResultMap.---Theerrorhappenedwhilesettingapropertyontheresultobject.---Cause:java.lang.NullPointerException;nestedexceptioniscom.ibatis.common.jdbc.exception.NestedSQLException:---Theerroroccurredincom/citycube/mabole/dao/resume/Resume.ibatis.xml.---Theerroroccurredwhileapplyingaresultmap.---ChecktheResume.getPositionMyFeaturedResume-AutoResultMap.---Theerrorhappenedwhilesettingapropertyontheresultobject.---Cause:java.lang.NullPointerException以下sqlmap配置文件:<selectid="getPositionMyFeaturedResume"resultClass="positionMyFeaturedResume"><![CDATA[SELECTDISTINCTmf.idas"myFeaturedResume.id",mf.gmt_modifiedas"myFeaturedResume.gmtmodified",mf.statusas"myFeaturedResume.status",mf.isdelas"myFeaturedResume.isdel",p.idas"position.id",p.nameas"position.name",f.idas"featuredResume.id",f.nameas"featuredResume.name",f.emailas"featuredResume.email",f.telas"featuredResume.tel",f.addressas"featuredResume.address"FROMmyfeatured_resumemfJOINpositionpONmf.position_id=p.idJOINfeatured_resumefONmf.featured_resume_id=f.idORDERBYmf.idDESC]]></select>

以下是resultClass对应的类PositionMyFeaturedResume:publicclassPositionMyFeaturedResumeextendsBaseObject{privatestaticfinallongserialVersionUID=8416864843075904656L;/***我的精选简历.<br/>*[这张表描述了Position与Featured_resume之间多对多的关系]*/privateMyFeaturedResumemyFeaturedResume;/***职位详细信息*/privatePositionposition;/***精选简历详细信息*/privateFeatured_resumefeaturedResume;publicMyFeaturedResumegetMyFeaturedResume(){returnmyFeaturedResume;}publicvoidsetMyFeaturedResume(MyFeaturedResumemyFeaturedResume){this.myFeaturedResume=myFeaturedResume;}publicPositiongetPosition(){returnposition;}publicvoidsetPosition(Positionposition){this.position=position;}publicFeatured_resumegetFeaturedResume(){returnfeaturedResume;}publicvoidsetFeaturedResume(Featured_resumefeaturedResume){this.featuredResume=featuredResume;}}

以下是action:FeaturedResumeRowHandlerrowHandler=null;rowHandler=(FeaturedResumeRowHandler)resumeDAO.getPositionMyFeaturedResume();List<PositionFeaturedResumes>list=rowHandler.getPositionFeaturedResumesList();

以下是DAO中的方法:publicRowHandlergetPositionMyFeaturedResume(){FeaturedResumeRowHandlerrowHandler=newFeaturedResumeRowHandler();this.getSqlMapClientTemplate().queryWithRowHandler("Resume.getPositionMyFeaturedResume",rowHandler);returnrowHandler;}

service层就省了。。。以下是rowhandlerpublicclassFeaturedResumeRowHandlerimplementsRowHandler{/***key-myFeaturedResumeID<br/>*value-MyFeaturedResume*/privateMap<Long,MyFeaturedResume>myFeaturedResumeMap=newHashMap<Long,MyFeaturedResume>();/***key-featuredResumeID<br/>*value-Featured_resume*/privateMap<Long,Featured_resume>featuredResumeMap=newHashMap<Long,Featured_resume>();/***key-positionID<br/>*value-PositionFeaturedResumes*/privateMap<Long,PositionFeaturedResumes>positionFeaturedResumesMap=newHashMap<Long,PositionFeaturedResumes>();/***List形式存储的PositionFeaturedResumes*/privateList<PositionFeaturedResumes>positionFeaturedResumesList=newArrayList<PositionFeaturedResumes>();publicvoidhandleRow(ObjectvalueObject){//=====================1.将查询结果转化为综合类PositionMyFeaturedResumepmfr=(PositionMyFeaturedResume)valueObject;//=====================2.获取各个属性MyFeaturedResumecurrentMyFeaturedResume=pmfr.getMyFeaturedResume();PositioncurrentPosition=pmfr.getPosition();Featured_resumecurrentFeaturedResume=pmfr.getFeaturedResume();//=====================3.判断各对象是否已存在.//3.1MyFeaturedResumeif(null==myFeaturedResumeMap.get(currentMyFeaturedResume.getId())){//3.1.1新的MyFeaturedResume,添加到对应的mapmyFeaturedResumeMap.put(currentMyFeaturedResume.getId(),currentMyFeaturedResume);}else{//3.1.2已存储,从map中获取MyFeaturedResumecurrentMyFeaturedResume=myFeaturedResumeMap.get(currentFeaturedResume.getId());}//3.2PositionFeaturedResumesPositionFeaturedResumespositionFeaturedResumes;if(null==positionFeaturedResumesMap.get(currentPosition.getId())){//3.2.1新的PositionFeaturedResumes,添加到对应的mappositionFeaturedResumes=newPositionFeaturedResumes();positionFeaturedResumes.setPosition(currentPosition);positionFeaturedResumesMap.put(currentPosition.getId(),positionFeaturedResumes);}else{//3.2.2已存储,从map中获取PositionFeaturedResumespositionFeaturedResumes=positionFeaturedResumesMap.get(currentPosition.getId());}//3.3Featured_resumeif(null==featuredResumeMap.get(currentFeaturedResume.getId())){//3.3.1新的Featured_resume,添加到对应的mapfeaturedResumeMap.put(currentFeaturedResume.getId(),currentFeaturedResume);}else{//3.3.2已存储,从map中获取Featured_resumecurrentFeaturedResume=featuredResumeMap.get(currentFeaturedResume.getId());}//=====================4.将currentFeaturedResume添加到列表positionFeaturedResumes.getFeaturedResumesList().add(currentFeaturedResume);positionFeaturedResumesList.add(positionFeaturedResumes);}publicList<PositionFeaturedResumes>getPositionFeaturedResumesList(){returnpositionFeaturedResumesList;}publicMap<Long,PositionFeaturedResumes>getPositionFeaturedResumesMap(){returnpositionFeaturedResumesMap;}}

框架是struts2+spring+ibatis。帮帮我吧,搞了一天了。。。

解决方案

本帖最后由 nightlove 于 2010-11-09 14:35:48 编辑
解决方案二:
resultClass="positionMyFeaturedResume">这是不是要加包名呢
解决方案三:
引用1楼jypapgl的回复:

resultClass="positionMyFeaturedResume">这是不是要加包名呢

不懂帮顶。类名不用大写开头吗
解决方案四:
引用2楼crazylaa的回复:

引用1楼jypapgl的回复:resultClass="positionMyFeaturedResume">这是不是要加包名呢不懂帮顶。类名不用大写开头吗

我有在前面配置过的,忘了写出来,如下:<typeAliasalias="positionMyFeaturedResume"type="com.city.model.resume.PositionMyFeaturedResume"/>

解决方案五:
引用1楼jypapgl的回复:

resultClass="positionMyFeaturedResume">这是不是要加包名呢

我有在前面配置过的,如下:<typeAliasalias="positionMyFeaturedResume"type="com.city.model.resume.PositionMyFeaturedResume"/>

解决方案六:
ibatis是个ORM框架吧,不了解,只能帮顶了
解决方案七:
引用5楼bgsbati1987的回复:

ibatis是个ORM框架吧,不了解,只能帮顶了

呵呵,谢了
解决方案八:
哎!好久没有用了,不过看那个错,感觉上是你返回的时候给属性设值出错的。---Theerroroccurredincom/citycube/mabole/dao/resume/Resume.ibatis.xml.---Theerroroccurredwhileapplyingaresultmap.---ChecktheResume.getPositionMyFeaturedResume-AutoResultMap.---Theerrorhappenedwhilesettingapropertyontheresultobject.
解决方案九:
另外我还想知道是不是这行为空指针异常。rowHandler=(FeaturedResumeRowHandler)resumeDAO.getPositionMyFeaturedResume();不是的话,那指明某行!!
解决方案十:
引用7楼jxsryecheng的回复:

哎!好久没有用了,不过看那个错,感觉上是你返回的时候给属性设值出错的。---Theerroroccurredincom/citycube/mabole/dao/resume/Resume.ibatis.xml.---Theerroroccurredwhileapplyingaresultmap.---ChecktheResume.getPosi……

谢谢你的回答!我给属性都设了值,原先不是AutoResultMap,是我自定义的ResultMap,根据先前我查网上的资料,对基本数据类型的字段设了nullValue="0",但还是有错,错误信息就那样,没有指明是哪个字段不能set,所以很无奈。但如果我不用rowHandler,改用queryForList之类的方法,就是正确的。。。
解决方案十一:
引用8楼jxsryecheng的回复:

另外我还想知道是不是这行为空指针异常。rowHandler=(FeaturedResumeRowHandler)resumeDAO.getPositionMyFeaturedResume();不是的话,那指明某行!!

我调试的时候,是在this.getSqlMapClientTemplate().queryWithRowHandler("Resume.getPositionMyFeaturedResume",rowHandler);

这里出错的,再调试,是在这里,org.springframework.orm.ibatis.SqlMapClientTemplate.javapublicObjectexecute(SqlMapClientCallbackaction)throwsDataAccessException{Assert.notNull(action,"Callbackobjectmustnotbenull");Assert.notNull(this.sqlMapClient,"NoSqlMapClientspecified");//WealwaysneedstouseaSqlMapSession,asweneedtopassaSpring-managed//Connection(potentiallytransactional)in.Thisshouldn'tbenecessaryif//werunagainstaTransactionAwareDataSourceProxyunderneath,butunfortunately//westillneedittomakeiBATISbatchexecutionworkproperly:IfiBATIS//doesn'trecognizeanexistingtransaction,itautomaticallyexecutesthe//batchforeverysinglestatement...SqlMapSessionsession=this.sqlMapClient.openSession();ConnectionibatisCon=null;try{if(logger.isDebugEnabled()){logger.debug("OpenedSqlMapSession["+session+"]foriBATISoperation");}ConnectionspringCon=null;try{ibatisCon=session.getCurrentConnection();if(ibatisCon==null){springCon=DataSourceUtils.getConnection(getDataSource());session.setUserConnection(springCon);if(logger.isDebugEnabled()){logger.debug("ObtainedJDBCConnection["+springCon+"]foriBATISoperation");}}else{if(logger.isDebugEnabled()){logger.debug("ReusingJDBCConnection["+ibatisCon+"]foriBATISoperation");}}returnaction.doInSqlMapClient(session);}catch(SQLExceptionex){throwgetExceptionTranslator().translate("SqlMapClientoperation",null,ex);}finally{DataSourceUtils.releaseConnection(springCon,getDataSource());}}finally{//OnlycloseSqlMapSessionifweknowwe'veactuallyopenedit//atthepresentlevel.if(ibatisCon==null){session.close();}}}

ibatisCon始终是null,所以有空指针异常

时间: 2024-10-22 04:42:31

ibatis中使用rowhandler并且在sqlmap中联合查询时出错:UncategorizedSQLException的相关文章

link中如何跨数据库和内存表联合查询?如何同时判断列表中多个元素的存在性?

问题描述 link中如何跨数据库和内存表联合查询?如何同时判断列表中多个元素的存在性? link中如何跨数据库和内存表联合查询?如何同时判断列表中多个元素的存在性? 解决方案 直接用数组是可以的. int[] ids = { 1, 2, 3, 4, 5 }; var query = from x in db.Table where ids.Contains(x) select x;

mfc opencv-MFC中使用opencv1.0同时打开三个摄像头时出错

问题描述 MFC中使用opencv1.0同时打开三个摄像头时出错 可以同时打开两个,但是当打开第三个的时候,就会发生错误,显示的错误信息(XP上)是:程序出错,需要进行调试.开始以为是三个摄像头的设备号(PID/VID)相同导致,采用的解决方案是在注册表HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlusbflags中添加,GlobalDisableSerNumGen=hex:01和IgnoreHWSerNum=hex:01两项,但是问题依然无法解

wcf 中nettcp使用x509证书,当IsOneWay=false 时出错

问题描述 接口定义[ServiceContract(SessionMode=SessionMode.Required,CallbackContract=typeof(IDataSourceCallback))]publicinterfaceIDataSource:IClientRegisterServices{[OperationContract(IsOneWay=true)]voidIsOnLine();[OperationContract(IsOneWay=false)]voidIsOnLi

dataset中根据条件多个表联合查询

问题描述 我是将一个复杂的xml文件加载到dataset中,dataset自动生成了好多表,并且给这些表之间生成了关系,然后怎么在dataset中进根据条件多个表联合查询.请高手解决!小弟在此谢谢了! 解决方案 解决方案二:你可以参考DataSet中进行Join操作http://www.cnblogs.com/chenxizhang/archive/2009/04/29/1445994.html在VisualC#.net中实现DataSetJOIN帮助器类http://support.micro

【奇怪】spring集成ibatis时,启动提示sqlmap中parameterClass的ClassNotFoundException,可是明明有啊。。。

问题描述 异常信息:十二月10,201412:11:23上午org.springframework.web.context.ContextLoaderinitWebApplicationContext严重:Contextinitializationfailedorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sqlMapClient'definedinServletContextre

Oracle+ibatis的&amp;amp;lt;select&amp;amp;gt;中resultClass是java.util.HashMap 返回结果key都是大写的变量名 如何解决

问题描述 如题:Oracle+ibatis的<select>中resultClass是java.util.HashMap 返回结果key都是大写的变量名 如何解决如果用resultClass用自定义的class可以解决,那么不同的多表查询岂不是要定义多个class来装这些结果集,即便是用resultMap还是得定义相关的配置,总不会每定义一个<select>(假设都是多表查询,而且都是不同的表),都要定义一个resultClass或者resultMap吧?我现在的问题是:用ibat

Python检测字符串中是否包含某字符集合中的字符

  这篇文章主要介绍了Python检测字符串中是否包含某字符集合中的字符,需要的朋友可以参考下 目的 检测字符串中是否包含某字符集合中的字符 方法 最简洁的方法如下,清晰,通用,快速,适用于任何序列和容器 代码如下: def containAny(seq,aset): for c in seq: if c in aset: return True return False 第二种适用itertools模块来可以提高一点性能,本质上与前者是同种方法(不过此方法违背了Python的核心观点:简洁,清

java-Jsp+Servlet怎么在form中指定要访问的servlet中的方法名

问题描述 Jsp+Servlet怎么在form中指定要访问的servlet中的方法名 Jsp+Servlet怎么在form中指定要访问的servlet中的方法名,在Jsp中写了一个form,然后想指定访问servlet中的regist()方法,而不是doGet()或者doPost()方法,应该怎么样指定 解决方案 servlet只能指定post,get请求,你随便请求一个,在调一下regist()呗,或者重写父类service方法,在里面加入regist() 解决方案二: dopost里面判断调

c语言数组与函数-如何在函数中给已经在主函数中定义好的数组赋值

问题描述 如何在函数中给已经在主函数中定义好的数组赋值 已经在main()中定义了一个长度为20的数组,想在定义的函数中给数组赋值,但一直报错,请问如何修改? void arrin(int *arr) { int i; arr[]={1,1,2,2,3,3,4,5,6,5,6,7,7,8,8,9,9,0,0}; for(i=0;i<20;i++) printf("%d",arr[i]); } main() { int testarr[20]; ............ } 解决方