关于hibernate 中query.list()空指针异常,急!!!!在线等,望达人解决下

问题描述

publicclassCollegeDaoImplTestextendsTestCase{publicvoidtestCollegeDaoImpl(){Sessionsession=HibernateUtils.getSession();session.beginTransaction();Queryquery=session.createQuery("selectcfromCollegec");for(inti=0;i<query.list().size();i++){Collegec=(College)query.list().get(i);System.out.println(c.getCollegeName());}session.getTransaction().commit();}}College类/***Thisiscollegeentity**@authorlpll*@hibernate.classtable="t_college"*/@SuppressWarnings("unchecked")publicclassCollege{/***collegeuniqueidentifierauto_increment**@hibernate.idgenerator-class="native"*/privateintid;/***college'sserialnumber**@hibernate.propertyunique="true"not-null="true"*/privateStringcollegeSerialNumber;/***college'sname**@hibernate.property*/privateStringcollegeName;/***collegeoffice**@hibernate.property*/privateStringcollegePlace;/***collegeincludestaffrooms**@hibernate.setlazy="extra"inverse="true"*@hibernate.keycolumn="collegeid"*@hibernate.one-to-manyclass="oa.dao.hbm.StaffRoom"*/privateSetstaffRooms;/***collegeincludemanyteachers**@hibernate.setlazy="flash"inverse="true"*@hibernate.keycolumn="collegeid"*@hibernate.one-to-manyclass="oa.dao.hbm.Teacher"*/privateSetteachers;publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetCollegeSerialNumber(){returncollegeSerialNumber;}publicvoidsetCollegeSerialNumber(StringcollegeSerialNumber){this.collegeSerialNumber=collegeSerialNumber;}publicStringgetCollegeName(){returncollegeName;}publicvoidsetCollegeName(StringcollegeName){this.collegeName=collegeName;}publicStringgetCollegePlace(){returncollegePlace;}publicvoidsetCollegePlace(StringcollegePlace){this.collegePlace=collegePlace;}publicSetgetStaffRooms(){returnstaffRooms;}publicvoidsetStaffRooms(SetstaffRooms){this.staffRooms=staffRooms;}publicSetgetTeachers(){returnteachers;}publicvoidsetTeachers(Setteachers){this.teachers=teachers;}}执行上面的测试程序会暴空指针异常java.lang.NullPointerExceptionatorg.hibernate.type.AbstractType.getHashCode(AbstractType.java:112)atorg.hibernate.type.AbstractType.getHashCode(AbstractType.java:120)atorg.hibernate.engine.EntityUniqueKey.generateHashCode(EntityUniqueKey.java:63)atorg.hibernate.engine.EntityUniqueKey.<init>(EntityUniqueKey.java:44)atorg.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)atorg.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)atorg.hibernate.loader.Loader.getRow(Loader.java:1206)atorg.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)atorg.hibernate.loader.Loader.doQuery(Loader.java:701)atorg.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)atorg.hibernate.loader.Loader.loadCollection(Loader.java:1994)atorg.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)atorg.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)atorg.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)atorg.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)atorg.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)atorg.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:797)atorg.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:241)atorg.hibernate.loader.Loader.doList(Loader.java:2220)atorg.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)atorg.hibernate.loader.Loader.list(Loader.java:2099)atorg.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)atorg.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)atorg.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)atorg.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)atorg.hibernate.impl.QueryImpl.list(QueryImpl.java:79)atoa.dao.impl.CollegeDaoImplTest.testCollegeDaoImpl(CollegeDaoImplTest.java:20)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)atjava.lang.reflect.Method.invoke(UnknownSource)atjunit.framework.TestCase.runTest(TestCase.java:164)atjunit.framework.TestCase.runBare(TestCase.java:130)atjunit.framework.TestResult$1.protect(TestResult.java:106)atjunit.framework.TestResult.runProtected(TestResult.java:124)atjunit.framework.TestResult.run(TestResult.java:109)atjunit.framework.TestCase.run(TestCase.java:120)atjunit.framework.TestSuite.runTest(TestSuite.java:230)atjunit.framework.TestSuite.run(TestSuite.java:225)atorg.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)但是其他的类就可以这样查询的,就这个类不行,配置文件也没问题,昨晚还可以的,就是今天不行了。。。。

解决方案

解决方案二:
怎么没人啊,急等啊,毕业设计自己先顶下
解决方案三:
hql查询语句写错了"fromCollegeasc"
解决方案四:
for(inti=0;i<query.list().size();i++){Collegec=(College)query.list().get(i);System.out.println(c.getCollegeName());}你怎么写要查多少次啊,换个写法试试吧~每次query.list()就查一下如果有n条记录你要查n+1次。
解决方案五:
publicclassCollegeDaoImplTestextendsTestCase{publicvoidtestCollegeDaoImpl(){Sessionsession=HibernateUtils.getSession();session.beginTransaction();Queryquery=session.createQuery("fromCollege");//Listlist=query.list();for(inti=0;i<list.size();i++){Collegec=(College)list().get(i);System.out.println(c.getCollegeName());}session.getTransaction().commit();}}
解决方案六:
publicclassCollegeDaoImplTestextendsTestCase{publicvoidtestCollegeDaoImpl(){Sessionsession=HibernateUtils.getSession();Queryquery=session.createQuery("fromCollege");System.out.println(query.list().size());}}

解决方案七:
确保你的list有数据?
解决方案八:
那些都不是主要的,表中也有数据,主要是会报这种异常严重:Servlet.service()forservletjspthrewexceptionjava.lang.NullPointerExceptionatorg.hibernate.type.AbstractType.getHashCode(AbstractType.java:112)atorg.hibernate.type.AbstractType.getHashCode(AbstractType.java:120)atorg.hibernate.engine.EntityUniqueKey.generateHashCode(EntityUniqueKey.java:63)atorg.hibernate.engine.EntityUniqueKey.<init>(EntityUniqueKey.java:44)atorg.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)atorg.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)atorg.hibernate.loader.Loader.getRow(Loader.java:1206)atorg.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)atorg.hibernate.loader.Loader.doQuery(Loader.java:701)atorg.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)atorg.hibernate.loader.Loader.loadEntity(Loader.java:1860)atorg.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)atorg.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)atorg.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)atorg.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)atorg.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)atorg.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)atorg.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)atorg.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)atorg.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)atorg.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)atorg.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)atorg.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)atoa.dao.hbm.StaffRoom$$EnhancerByCGLIB$$65968924.getStaffRoomName(<generated>)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)atjava.lang.reflect.Method.invoke(UnknownSource)atjavax.el.BeanELResolver.getValue(BeanELResolver.java:62)atjavax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)atorg.apache.el.parser.AstValue.getValue(AstValue.java:118)atorg.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)atorg.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)atorg.apache.jsp.admin.user.userIndex_jsp._jspService(userIndex_jsp.java:471)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)atorg.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)atorg.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)atorg.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)atorg.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)atorg.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)atorg.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)atorg.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)atorg.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:617)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atoa.filter.CharacterFilter.doFilter(CharacterFilter.java:30)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atoa.filter.OffsetAndPageSizeFilter.doFilter(OffsetAndPageSizeFilter.java:28)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)atjava.lang.Thread.run(UnknownSource)其他的类都可以,就是跟有关College的类就会出现这种异常
解决方案九:
是配置的问题的,正常情况是可能做到级联保存,但查询会出问题,里面是多对一的问题,我只知道问题出在这里,但没好的方法解决,也许是Hibernate一个足的地方吧!

时间: 2024-10-25 10:48:31

关于hibernate 中query.list()空指针异常,急!!!!在线等,望达人解决下的相关文章

解决方案-php 中curl 35号错误,在线等大神解决

问题描述 php 中curl 35号错误,在线等大神解决 如图,结果返回的信息是求解决方案 解决方案 CURLE_SSL_CONNECT_ERROR (35) A problem occurred somewhere in the SSL/TLS handshake. You really want the error buffer and read the message there as it pinpoints the problem slightly more. Could be cer

聊天-Android开发中遇到了一个问题,求大神解决下。

问题描述 Android开发中遇到了一个问题,求大神解决下. 我现在将别人写好的聊天软件,根据我自己的需要,剔除了很多不用的activity和功能,然后当成Library.我遇到的问题是,我现在只有进入到这个聊天界面才能够收到信息和来信息的提示,如果我不进入,我就没法得到来消息的提示,请问我该怎么解决呢? 解决方案 就想QQ的离线消息一样?后台起一个Service接收信息,有信息了就在消息通知栏里放一个消息. 解决方案二: 这个问题可能涉及到通知提醒的内容,建议你先看一下android是如何实现

如何把NOTES8邮箱整合进OA系统中的问题,急(要求一天解决)!!!!!

问题描述 公司现在接了个OA系统的项目,是用JAVA开发一个B/S架构的OA系统,客户要求把NOTES8邮箱整合进OA系统中,各位有做过或未做过的高手有什么最简便的实现方案能提供下吗,先谢谢了!!! 解决方案 解决方案二:是was吗?如果是的话,可以导出一个KEY文件,然后导入到OA系统中,然后做web-sso,这不是一天能解决的问题~解决方案三:谢谢你了哈,还是有点不明白,之后跟他们确认了下,是以WEB形式访问notes,notes支持web形式的访问,再在OA系统中封装一下访问地址,这有可能

图片上传中的复制问题~~~急!!!在线等....

问题描述 voidcopy(Filef1,Filef2){//f1源文件路径f2目标路径最后把f2insert到数据库就不写了try{//建立相关的字节输入流FileInputStreamfr=newFileInputStream(f1);//通过打开一个到实际文件的连接来创建一个//FileInputStream,该文件通过文件系统中的路径名//创建一个向具有指定名称的文件中写入数据的输出文件流.FileOutputStreamfw=newFileOutputStream(f2);bytebu

mvc模式的extjs4中pannel多选问题(在线等 急)

问题描述 mvc模式的extjs4中pannel多选问题(在线等 急) 需求:我需要在查询列表面板panel中添加多选项,并可以通过点击查询面板panel上的按钮获取查询列表面板的所有选中值. 现象:方法一.我使用selModel : new Ext.selection.CheckboxModel(),点击查询面板的按钮可以获取到多选值,通过弹出框显示出来,但是关闭弹出框以后,只能通过表头的多选框进行全选或取消全选,单击列表中的个别行或行前的多选框就没反应: 方法二.我使用selModel :

请问这个C++的dll在C#中怎么调呀?急……在线等!

问题描述 请问这个C++的dll在C#中怎么调呀?急--在线等! C++中的调用: extern "C" _declspec(dllimport) int ReadGzjzzData(char* pData,char* photo,int * iErrCode); void CReadGzjzzDlg::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 // OnOK(); char Data[64*1024] = {0};//各字段用双竖"

在Hibernate中检索策略的应用详解

Hibernate的检索策略包括类级别检索策略和关联级别检索策略. 类级别检索策略有立即检索和延迟检索,默认的检索策略是立即检索.在Hibernate映射文件中,通过在<不着class>上配置lazy属性来确定检索策略.对于Session的检索方式,类级别检索策略仅适用于load方法:也就说,对于get.qurey检索,持久化对象都会被立即加载而不管lazy是false还是true.一般来说,我们检索对象就是要访问它,因此立即检索是通常的选择.由于load方法在检索不到对象时会抛出异常(立即检

jsp-百度编辑器1.4.3JSP版 如何修改文件上传路径?急在线等

问题描述 百度编辑器1.4.3JSP版 如何修改文件上传路径?急在线等 RT 默认的上传路径在重启Tomcat的时候会造成图片丢失的情况,请问该如何修改百度编辑器的文件上传路径 急........................在线等 解决方案 在ueditor/jsp/config.json中的 "imagePathFormat": "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存

一个空指针异常问题,求大神帮忙解决下,在线等

问题描述 一个空指针异常问题,求大神帮忙解决下,在线等 public void getQaList(String type, String qid, String qid_min, String cat_id, String tag_id, String page, String qid_top, boolean isShowLoadingDialog) { List<RequestParameter> parameter = new ArrayList<RequestParameter