问题描述
现在我由于不得已操作中间表 在做分页的时候 总是报ERROR - ORA-00918: 未明确定义列 但是做搜索全部的时候却不会报 在这里请教下各位!!java code: public List<Coandma> getCoandmaFenye(final int pageNo, final int pageSize,final int cid) throws Exception {List<Coandma> list = (List<Coandma>) this.getHibernateTemplate().executeFind(new HibernateCallback() {public Object doInHibernate(Session session)throws HibernateException, SQLException {Query query = session.createQuery("from Coandma coandma where coandma.cid=?");query.setParameter(0, cid);query.setFirstResult(pageNo * (pageSize)).setMaxResults(pageSize);return query.list();}});return list;}hbm.xml <class name="com.kinrich.mediaStorage.dto.Coandma" table="COANDMA" schema="SCOTT"> <id name="id" type="java.lang.Integer"> <column name="ID" precision="22" scale="0" /> <generator class="increment"></generator> </id> <property name="cid" type="java.lang.Integer"> <column name="CID" precision="22" scale="0" /> </property> <property name="maid" type="java.lang.Integer"> <column name="MAID" precision="22" scale="0" /> </property> <property name="telphone" type="java.lang.Integer"> <column name="TELPHONE" precision="22" scale="0" /> </property> <property name="email" type="java.lang.Integer"> <column name="EMAIL" precision="22" scale="0" /> </property> <property name="newspaper" type="java.lang.Integer"> <column name="NEWSPAPER" precision="22" scale="0" /> </property> <property name="yangbao" type="java.lang.Integer"> <column name="YANGBAO" precision="22" scale="0" /> </property> <property name="payment" type="java.lang.Integer"> <column name="PAYMENT" precision="22" scale="0" /> </property> <many-to-one name="manuscript" class="com.kinrich.mediaStorage.dto.Manuscript"> <column name="maid" precision="22" scale="0" /> </many-to-one> <many-to-one name="contact" class="com.kinrich.mediaStorage.dto.Contact"> <column name="cid" precision="22" scale="0" /> </many-to-one> </class>错误 org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute queryat org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:615)at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343)at com.kinrich.mediaStorage.daoimp.CoandmaDaoImp.getCoandmaFenye(CoandmaDaoImp.java:28)at com.kinrich.mediaStorage.action.CoandmaAction.getList(CoandmaAction.java:35)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.Method.invoke(Unknown Source)at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at com.kinrich.mediaStorage.Interceptor.CheckInterceptor.doFilter(CheckInterceptor.java:38)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)at java.lang.Thread.run(Unknown Source)希望能各位能帮下 谢谢了!! 都搞了一个星期了 就是弄不出来 问题补充:Rainbow702 写道
解决方案
引用org.hibernate.dialect.Oracle9Dialect你的数据库是 oracle 9i 的么?
解决方案二:
那你搜一下 hibernate.dialect 看看
解决方案三:
工程中应有引用 hibernate.properties 或 hibernate.cfg.xml 二者之一
解决方案四:
另外,看一下你的 hibernate.dialect 这个值是不是 org.hibernate.dialect.OracleDialect
解决方案五:
引用去掉报缺少表达式不会吧,是不是你忘了删结尾的 逗号 了?
解决方案六:
不明白,下面这个为什么会要写两遍:引用# coandma0_.maid as maid2_, # coandma0_.cid as cid2_ 只是大小写不同而已。我认为,父查询在根据这个子查询进行查询的时候,发现子查询中有两对列名是一样的,导致它无法确定查找哪一列,从而报了这个异常。参见: http://king520.iteye.com/blog/895216
解决方案七:
这问题太奇怪了不会是引用 coandma0_.ID as ID2_, 不会是这个ID取名的问题吧,反正 sqlserver有这个问题,但是oracle应该不会啊 晕
解决方案八:
引用# select # aaa.* # from # ( select # coandma0_.ID as ID2_, # coandma0_.CID as CID2_, # coandma0_.MAID as MAID2_, # coandma0_.TELPHONE as TELPHONE2_, # coandma0_.EMAIL as EMAIL2_, # coandma0_.NEWSPAPER as NEWSPAPER2_, # coandma0_.YANGBAO as YANGBAO2_, # coandma0_.PAYMENT as PAYMENT2_, # coandma0_.maid as maid2_, # coandma0_.cid as cid2_ # from # SCOTT.COANDMA coandma0_ # where # coandma0_.CID=? ) aaa# where # rownum <= ? 把上面的引用# coandma0_.maid as maid2_, # coandma0_.cid as cid2_ 这两句去掉,试试呢
解决方案九:
在里面那个 where里面 加一个rownum>5外面 rownum<10
解决方案十:
那你改为这个呢:引用# select # aaa.* # from # ( select # coandma0_.ID as ID2_, # coandma0_.CID as CID2_, # coandma0_.MAID as MAID2_, # coandma0_.TELPHONE as TELPHONE2_, # coandma0_.EMAIL as EMAIL2_, # coandma0_.NEWSPAPER as NEWSPAPER2_, # coandma0_.YANGBAO as YANGBAO2_, # coandma0_.PAYMENT as PAYMENT2_, # coandma0_.maid as maid2_, # coandma0_.cid as cid2_ # from # SCOTT.COANDMA coandma0_ # where # coandma0_.CID=? ) aaa# where # rownum <= ?
解决方案十一:
引用# select # * # from # ( select # coandma0_.ID as ID2_, # coandma0_.CID as CID2_, # coandma0_.MAID as MAID2_, # coandma0_.TELPHONE as TELPHONE2_, # coandma0_.EMAIL as EMAIL2_, # coandma0_.NEWSPAPER as NEWSPAPER2_, # coandma0_.YANGBAO as YANGBAO2_, # coandma0_.PAYMENT as PAYMENT2_, # coandma0_.maid as maid2_, # coandma0_.cid as cid2_ # from # SCOTT.COANDMA coandma0_ # where # coandma0_.CID=? ) # where # rownum <= ? 你直接把这个语句搬到 oracle 中去运行看它报不报错。注意修改一下表名和 ? 的值。
解决方案十二:
引用Query query = session.createQuery("from Coandma coandma where coandma.cid=?"); 它产生的SQL语句应该会在控制台打印出来的吧,你把它贴出来看看呢?
解决方案十三:
引用去掉 setFirstResult报错 Caused by: java.sql.SQLException: 对只转发结果集的无效操作: absolute 那你等于说直接取得就不行?不分页的时候就不行?引用而且 我那是Oracle操作 我那样的sql语句可以执行的 就没有必要去加as了 no 你试试吧
解决方案十四:
你的 coandma.cid 是什么类型的?
解决方案十五:
引用我试了你说的方法 不行 还是报那个错误 加 as
解决方案:
引用Query query = session.createQuery("from Coandma coandma where coandma.cid=?"); query.setParameter(0, cid); 改为 Query query = session.createQuery("from Coandma coandma where coandma.cid=?"); query.setInteger(0, new Integer(cid));或者:Query query = session.createQuery("from Coandma coandma where coandma.cid= :tempCid"); query.setParameter("tempCid", new Integer(cid));试试
解决方案:
假如不加后面的setFirstResult,也就是直接取所有可以吗?应该改成from Coandma as coandma where coandma.cid=?"或者直接 from Coandma where cid=?"