`
flashdream8
  • 浏览: 680635 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

SQLState: S0022

 
阅读更多

SQLState: S0022

 

	StringBuffer sb = new StringBuffer();
		sb.append(" select  {m.*}   from d_provider_to_factory as d , m_enterprice  as m where  1=1 ");
		if ("0".equals(enterpriceType)) {
			sb.append(" and  d.provider_id = m.enterprice_id ");
		}else if("1".equals(enterpriceType)){
			sb.append(" and d.factory_id = m.enterprice_id ");
		}
		sb.append(" and  m.flag_del = '0' ");
		sb.append(" and  d.flag_del = '0' ");
		
		if ("0".equals(enterpriceType)) {
			sb.append(" group by   d.provider_id  ");
		}else if("1".equals(enterpriceType)){
			sb.append(" group by  d.factory_id ");
		}
		
		if (page <=0) {
			page = 1;
		}
		
		String sql = sb.toString();
		sb = null;
		Session session = getSession();
	    List  pList = session.createSQLQuery(sql)
			.addEntity("d", DProviderToFactory.class)
			.addEntity("m",MEnterprice.class)
			.setFirstResult((page-1)*pageSize)
			.setMaxResults(pageSize)
			.list();

 

执行的时候 报错:

Hibernate: 
    select
        m.enterprice_id as enterprice1_84_1_,
        m.enterprice_name as enterprice2_84_1_,
        m.enterprice_short_name as enterprice3_84_1_,
        m.enterprice_original_name as enterprice4_84_1_,
        m.parent_enterprice_id as parent5_84_1_,
        m.trade_type as trade6_84_1_,
        m.province_id as province7_84_1_,
        m.administrative_division as administ8_84_1_,
        m.address as address84_1_,
        m.post_code as post10_84_1_,
        m.enterprise_type as enterprise11_84_1_,
        m.corporate_representative as corporate12_84_1_,
        m.fax as fax84_1_,
        m.phone_number as phone14_84_1_,
        m.cell_phone_number as cell15_84_1_,
        m.email as email84_1_,
        m.begin_date as begin17_84_1_,
        m.register_capital as register18_84_1_,
        m.operate_begin_date as operate19_84_1_,
        m.operate_end_date as operate20_84_1_,
        m.register_department as register21_84_1_,
        m.tax_number as tax22_84_1_,
        m.register_code as register23_84_1_,
        m.operate_area as operate24_84_1_,
        m.remark as remark84_1_,
        m.flag_del as flag26_84_1_,
        m.create_datetime as create27_84_1_,
        m.create_date_user as create28_84_1_,
        m.update_datetime as update29_84_1_,
        m.update_date_user as update30_84_1_   
    from
        d_provider_to_factory as d ,
        m_enterprice  as m 
    where
        1=1  
        and d.factory_id = m.enterprice_id  
        and  m.flag_del = '0'  
        and  d.flag_del = '0'  
    group by
        d.factory_id 
2011-07-06 15:44:29,595 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: S0022
2011-07-06 15:44:29,595 ERROR [org.hibernate.util.JDBCExceptionReporter] - Column 'provider1_83_0_' not found.
org.hibernate.exception.SQLGrammarException: could not execute query
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	at org.hibernate.loader.Loader.doList(Loader.java:2223)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
	at org.hibernate.loader.Loader.list(Loader.java:2099)
	at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
	at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
	at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
	at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
	at cn.com.jdlh.enterprice.dao.EnterPriceDAO.getEnterPriceList(EnterPriceDAO.java:62)
	at cn.com.jdlh.enterprice.dao.EnterPriceDAO$$FastClassByCGLIB$$4c9aae10.invoke(<generated>)
	at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
	at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
	at cn.com.jdlh.enterprice.dao.EnterPriceDAO$$EnhancerByCGLIB$$dffb0954.getEnterPriceList(<generated>)
	at cn.com.jdlh.enterprice.action.EnterPriceAction.enterPriceList(EnterPriceAction.java:30)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
	at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
	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:236)
	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	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:236)
	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:236)
	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	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:236)
	at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
	at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at filters.SecurityFilter.doFilter(SecurityFilter.java:105)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:163)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:556)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:267)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:245)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:260)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: Column 'provider1_83_0_' not found.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
	at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:987)
	at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2749)
	at com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2573)
	at org.hibernate.type.IntegerType.get(IntegerType.java:28)
	at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
	at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
	at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1097)
	at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)
	at org.hibernate.loader.Loader.doQuery(Loader.java:701)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
	at org.hibernate.loader.Loader.doList(Loader.java:2220)
	... 95 more

 

 

 

我将 Hibernate 打印出来的SQL 拿出来可以单独执行,但是 放到程序里就出错了。

 

 

最后找到问题根源

 

 

   List pList = session.createSQLQuery(sql)
			//.addEntity("d", DProviderToFactory.class)
			.addEntity("m",MEnterprice.class)
			.setFirstResult((page-1)*pageSize)
			.setMaxResults(pageSize)
			.list();
	    

 

因为 我不需要 查询出 d 实体的内容 所以 就不用吧 d也实例化 将

//.addEntity("d", DProviderToFactory.class)

 

注释掉 就可以了。

 

如果不注释掉 也行 就修改sql 语句

 

StringBuffer sb = new StringBuffer();
		sb.append(" select  {m.*} ,{d.*}  from d_provider_to_factory as d , m_enterprice  as m where  1=1 ");
		if ("0".equals(enterpriceType)) {
			sb.append(" and  d.provider_id = m.enterprice_id ");
		}else if("1".equals(enterpriceType)){
			sb.append(" and d.factory_id = m.enterprice_id ");
		}
		sb.append(" and  m.flag_del = '0' ");
		sb.append(" and  d.flag_del = '0' ");
		
		if ("0".equals(enterpriceType)) {
			sb.append(" group by   d.provider_id  ");
		}else if("1".equals(enterpriceType)){
			sb.append(" group by  d.factory_id ");
		}
		
		if (page <=0) {
			page = 1;
		}
		
		String sql = sb.toString();
		sb = null;
		Session session = getSession();
	    List  pList = session.createSQLQuery(sql)
		.addEntity("d", DProviderToFactory.class)
		.addEntity("m",MEnterprice.class)
		.setFirstResult((page-1)*pageSize)
		.setMaxResults(pageSize)
		.list();
	    

 

 

总结:如果非要用hibernate查询sql 语句并且进行自动映射的话,最好用到那个实体就添加那个实体。

分享到:
评论

相关推荐

    SQLState错误码查表

    SQLSTATE 错误码查表 SQLSTATE 错误码是 SQL 语句执行过程中出现的错误代码,它们是标准化的错误代码,可以帮助开发者快速地定位和解决问题。本文档提供了 SQLSTATE 错误码的详细信息,包括错误代码、错误描述和...

    MySQL Error Code文档手册

    * Error 1009:SQLSTATE: HY000 (ER_DB_DROP_DELETE) Message: Error dropping database (can't delete '%s', errno: %d) * Error 1010:SQLSTATE: HY000 (ER_DB_DROP_RMDIR) Message: Error dropping database (can...

    数据库错误代码和消息

    - **消息**:`将 '%s' 重命名为 '%s' 时出错 (errno:%d)` - **解释**:在尝试重命名文件时遇到错误,可能是由于目标文件已存在或其他权限问题。 27. **错误:1026 SQLSTATE: HY000 (ER_ERROR_ON_WRITE)** - **...

    GBase 8s SQL 指南:教程

    **GBase 8s SQL 指南:教程** GBase 8s是南大通用数据系统有限公司开发的一款高性能、高可用性的国产化数据库管理系统,主要用于满足大规模数据处理和分析的需求。作为一款关系型数据库,它支持SQL(结构化查询语言...

    关键字user附近有语法错误解决方案

    警告: SQL Error: 156, SQLState: S0001 org.hibernate.exception.SQLGrammarException: could not execute query org.hibernate.util.JDBCExceptionReporter logExceptions 严重: 关键字 'user' 附近有语法错误。...

    对表进行任何操作都不被允许,提示SQLSTATE=57016 SQLCODE=-668 ,原因码 \"7\"的错误:SQL0668N Operation not

    在SQL数据库操作中,我们可能会遇到各种错误代码,其中SQLSTATE=57016 SQLCODE=-668是一个常见的错误,特别是在IBM DB2数据库系统中。这个错误通常表示一个操作无法执行,因为对象(如表)正被其他事务占用或者处于...

    GBase 8s 消息手册.pdf

    - **1004 SQLSTATE: HY000**:信息为“Can't create file '%s' (errno: %d)”,表明无法创建指定文件,其中的 `%s` 和 `%d` 分别代表文件名和错误码。 - **1005 SQLSTATE: HY000**:信息为“Can't create table '%s'...

    SQL Codes Decoded.ppt

    - "Batch Abend Codes"中的Sxxx Uxxxx:S代表“系统”,U代表“用户”。例如,"subscript out of range"意味着访问COBOL数组时下标越界,可能导致内存破坏和后续错误。 7. **解决问题**: - 分析SQLCode和...

    db2 错误信息查询

    #### SQLSTATE消息概述 在DB2中,SQLSTATE是一种标准的错误报告机制,用于指示SQL语句执行时的状态。这些状态被编码为五字符的字母数字组合,用于帮助诊断问题。每个状态都有特定的意义,并对应于不同的错误或警告...

    SQL错误代码大全.pdf

    错误提示“(s)netlib”表明在执行网络操作时出现了问题。 4. SQLSetPos:这是SQL Server中的一个API函数,用于定位在结果集中的行,并且设置行的锁定模式。文档中多次提到SQLSetPos,可能在某些操作中因为定位或...

    MySQL错误码大全.pdf

    错误消息:将'%s'重命名为'%s'时出错(errno:%d) 解释:在尝试重命名文件时发生错误,原因可能是权限不足或目标文件名已存在。 27. ER_ERROR_ON_WRITE(错误码:1026) 错误消息:写入文件'%s'时出错(errno:%d) 解释...

    mysql常见错误与标准错误对照表.docx

    这份文档,"mysql常见错误与标准错误对照表.docx",提供了一个详细的错误代码和对应的SQLSTATE代码,帮助用户理解和解决MySQL中遇到的问题。以下是部分常见的MySQL错误及其解释: 1. **错误1011HY000**: "Error on ...

    DB2存储过程

    CAST(s_rtcd AS CHAR(5)) || '--sqlstate:' || s_rtst; -- 进一步处理或退出 END IF; END; ``` #### 五、命名规范 **1. 存储过程命名** - 命名应简短且有意义,最好能反映存储过程的功能。 - 遵循一定的命名...

    Gbase常见问题 Gbase常见问题

    **问题描述**:通过Gbase JDBC连接单个数据库时出现异常:“SQLException: Server configuration denies access to data source, SQLState: 08001, VendorError: 0”。 **解决方案**: 1. **权限检查**:首先确保...

    参考手册-表格.pdf

    Adaptive Server Enterprise ...,%)-./ 012) SQLSTATE 34 56789:; &gt;? Transact-SQL @ABC:DEFG#$H I JKL M &gt;?NOPQR Transact-SQL S TU V WX YZ S[\&gt;? Transact-SQL ]^ _`ab c

    sql server 2812错误处理

    ### SQL Server 2812错误处理 #### 一、问题背景 在SQL Server数据库管理过程中,用户可能会遇到“错误2812:未能找到存储过程'master.dbo.xp_fileexist'”的问题。该问题通常发生在尝试还原数据库时,其原因是系统...

    MYSQL测试题

    SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = '课程名不能与其他课程相同'; END IF; END$$ DELIMITER ; ``` #### 六、用户与权限管理(10分) - **知识点**: 使用`GRANT`语句创建用户并授予权限。 - **示例**...

Global site tag (gtag.js) - Google Analytics