问题描述
错误信息如下: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,所以有空指针异常