StringBuffer sql = new StringBuffer();
sql.append("select ");
sql.append(" g.OBJ_ID as objId ");
sql.append(" from GMDJB g ");
sql.append(" where 1=1 ");
SQLQuery query =getSession().createSQLQuery(sql.toString());
query.setProperties(hqlp);
List list = query.list();
执行报错
Hibernate: select g.OBJ_ID as objId from GMDJB g where 1=1 order by g.UPLOAD_TIME desc limit ?
2014-11-29 17:46:25,241 INFO hibernate.type.StringType:203 -> could not read column value from result set: obj_id; Column 'obj_id' not found.
2014-11-29 17:46:25,486 WARN hibernate.util.JDBCExceptionReporter:100 -> SQL Error: 0, SQLState: S0022
2014-11-29 17:46:25,487 ERROR hibernate.util.JDBCExceptionReporter:101 -> Column 'obj_id' not found.
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1723)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)
at ztb.dao.GmdjbDao.findGmdjb(GmdjbDao.java:64)
at ztb.service.GmdjbService.findGmdjb(GmdjbService.java:29)
at ztb.service.GmdjbService$$FastClassByCGLIB$$9628745e.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:628)
at ztb.service.GmdjbService$$EnhancerByCGLIB$$55314ef9.findGmdjb(<generated>)
at ztb.action.GmdjbAction.list(GmdjbAction.java:65)
at sun.reflect.GeneratedMethodAccessor177.invoke(Unknown Source)
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: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 sys.action.AvailableInterceptor.intercept(AvailableInterceptor.java:58)
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 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:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
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:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:880)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:719)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2081)
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 'obj_id' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1163)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5729)
at org.hibernate.type.StringType.get(StringType.java:41)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:210)
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:497)
at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:443)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:340)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:629)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
... 89 more
但是把这个sql语句复制到mysql上执行没问题。
select g.OBJ_ID as objId from GMDJB g where 1=1 order by g.UPLOAD_TIME desc limit 10
只查没有下划线的字段都没问题 ,一加上下划线就出问题。有谁遇到过吗?
相关推荐
在Java的持久化框架Hibernate中,SQLQuery是用于执行自定义SQL语句的重要工具,它允许开发者绕过ORM(对象关系映射)的抽象层,直接与数据库进行交互。这篇博客"Hibernate SQLQuery 本地查询"可能详细讲解了如何利用...
总结,Hibernate的SQLQuery接口提供了对原生SQL查询的强大支持,我们可以方便地设置查询参数、处理查询结果,甚至自定义结果集的转换方式。通过灵活运用这些功能,开发者可以在保持ORM优势的同时,处理那些不适合HQL...
hibernate sql hqlsql
### Hibernate SQLQuery 查询Oracle char类型结果为一个字符的解决方法 在使用Hibernate框架结合Oracle数据库进行数据查询时,经常会遇到一个问题:当查询的结果集中包含char类型的字段时,Hibernate可能会将其映射...
在某些情况下,开发者可能需要使用原生SQL查询来执行特定的数据库操作,这时就可以利用Hibernate的SQLQuery功能。本文将详细讲解如何使用Hibernate的SQLQuery进行本地SQL查询。 首先,创建SQLQuery实例是通过...
在实际开发中,我们可能需要执行一些复杂的 SQL 查询,或者使用数据库特有的函数和语句,而这些操作在 HQL 中不支持。此时,我们需要使用原生 SQL 语句来实现这些操作。 使用 Hibernate 执行原生 SQL 语句 ...
在Java开发中,Hibernate作为一个非常流行的ORM框架,提供了多种查询方式,其中就包括了HQL(Hibernate Query Language)和原生SQL查询。本文将针对给定代码片段中的核心知识点——如何在Hibernate中使用原生SQL而非...
fix包 博文链接:https://raymondhekk.iteye.com/blog/250427
在Hibernate中,我们通常使用HQL(Hibernate Query Language)或Criteria API进行查询,但这些方式并不支持复杂的动态查询。为了实现动态SQL,我们可以借助于Hibernate的QBC(Query By Criteria)和Criteria API,...
首先,让我们了解一下Hibernate中的HQL(Hibernate Query Language),它是Hibernate提供的面向对象的查询语言,类似于SQL,但更贴近于Java。在HQL中,我们可以方便地使用聚合函数进行数据处理。例如,如果你想要...
首先,本地SQL查询(Native SQL)是指直接在Hibernate中使用原生的SQL语句进行查询,而不是使用HQL(Hibernate Query Language)。这允许开发者充分利用SQL的功能,比如进行复杂的统计计算或者处理特定数据库的特性...
总结来说,Hibernate的SQLQuery接口提供了丰富的功能,支持本地SQL查询,处理字段冲突,加载关联对象,返回标量值或混合结果,以及利用结果集映射和命名SQL查询来提高代码的可读性和复用性。在实际开发中,灵活运用...
在这个“hibernate 实践 - Query详解”的主题中,我们将深入理解如何使用Query接口来执行SQL查询,并绑定参数。 1. **Query接口** Query接口是Hibernate提供的一种用于执行HQL(Hibernate查询语言)或SQL查询的API...
综上所述,通过正确配置Hibernate的`hibernate.show_sql`、`hibernate.format_sql`以及日志框架的设置,我们可以得到不带问号的完整SQL输出,以辅助开发和调试工作。在实际项目中,可以参考上述步骤进行设置,确保你...
查询数据的方法有两种实现,一种是基于HQL(Hibernate Query Language),另一种是基于原生SQL。 - 基于HQL的通用查询: HQL是Hibernate提供的面向对象的查询语言,可以方便地操作对象和属性。`select`方法接收一个...
在Java的持久化框架Hibernate中,执行原生SQL(Native SQL)是常见需求,尤其是在处理特定数据库特性或者优化性能时。本篇文章将详细介绍在Hibernate中执行原生SQL的几种方式,以及它们各自的适用场景和优缺点。 1....
3. **JDBC版本兼容性**: 注意,由于SQL Server 2000比较旧,可能不支持最新的JDBC驱动。你可能需要使用特定于该版本的JDBC驱动,例如`com.microsoft.jdbc.sqlserver.SQLServerDriver`。 4. **Dialect设置**: ...
在 Hibernate 中,使用 SQLQuery 可以执行 Native SQL 查询,控制查询的执行是通过 SQLQuery 接口进行的,通过执行 Session.createSQLQuery() 获取这个接口。下面将详细介绍如何使用这个 API 进行查询。 标量查询...