zoukankan      html  css  js  c++  java
  • hibernate mysql 分页时报错 显示的代码和sql server 类似 select top 1……

    [ERROR][com.alibaba.druid.filter.stat.StatFilter]merge sql error, dbType mysql, sql : 
    select top 1 ddiary0_.diary_id as diary_id1_9_, ddiary0_.site_id as site_id26_9_, ddiary0_.catalog_id as catalog27_9_, ddiary0_.user_id as user_id28_9_, ddiary0_.annex_id as annex_id2_9_, ddiary0_.client_agent as client_a3_9_, ddiary0_.client_ip as client_i4_9_, ddiary0_.client_type as client_t5_9_, ddiary0_.content as content6_9_, ddiary0_.contribute as contribu7_9_, ddiary0_.diary_size as diary_si8_9_, ddiary0_.ext1 as ext9_9_, ddiary0_.ext2 as ext10_9_, ddiary0_.ext3 as ext11_9_, ddiary0_.ext4 as ext12_9_, ddiary0_.last_read_time as last_re13_9_, ddiary0_.last_reply_time as last_re14_9_, ddiary0_.locked as locked15_9_, ddiary0_.modify_time as modify_16_9_, ddiary0_.mood_level as mood_le17_9_, ddiary0_.reply_count as reply_c18_9_, ddiary0_.reply_notify as reply_n19_9_, ddiary0_.role as role20_9_, ddiary0_.type_id as type_id29_9_, ddiary0_.tag as tag21_9_, ddiary0_.title as title22_9_, ddiary0_.txt as txt23_9_, ddiary0_.view_count as view_co24_9_, ddiary0_.write_time as write_t25_9_ from wxs.d_diary ddiary0_ where ddiary0_.diary_id<? and ddiary0_.user_id=? order by ddiary0_.diary_id desc1068481ncom.alibaba.druid.sql.parser.ParserException: syntax error, error in :' top 1 ddiary0_.diary_id as diary_i',expect LITERAL_INT, actual LITERAL_INT top
    	at com.alibaba.druid.sql.parser.SQLParser.printError(SQLParser.java:210)
    	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:307)
    	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:112)
    	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:107)
    	at com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils.parameterize(ParameterizedOutputVisitorUtils.java:54)
    	at com.alibaba.druid.filter.stat.StatFilter.mergeSql(StatFilter.java:145)
    	at com.alibaba.druid.filter.stat.StatFilter.createSqlStat(StatFilter.java:629)
    	at com.alibaba.druid.filter.stat.StatFilter.statementPrepareAfter(StatFilter.java:305)
    	at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:124)
    	at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448)
    	at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342)
    	at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:318)
    	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:162)
    	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
    	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160)
    	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1885)
    	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
    	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
    	at org.hibernate.loader.Loader.doQuery(Loader.java:910)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
    	at org.hibernate.loader.Loader.doList(Loader.java:2554)
    	at org.hibernate.loader.Loader.doList(Loader.java:2540)
    	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
    	at org.hibernate.loader.Loader.list(Loader.java:2365)
    	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
    	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
    	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
    	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
    	at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
    	at com.cx.wxs.base.dao.BaseDaoImpl.get(BaseDaoImpl.java:557)
    	at com.cx.wxs.dao.impl.DDiaryDaoImpl.getCurrentDiarys(DDiaryDaoImpl.java:171)
    	at com.cx.wxs.service.impl.DDiaryServiceImpl.getCurrentDiarys(DDiaryServiceImpl.java:92)
    	at com.cx.wxs.action.diary.diaryAction.articlePreview(diaryAction.java:139)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at com.cx.wxs.filter.SessionFilter.doFilterInternal(SessionFilter.java:147)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:151)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
    	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	at java.lang.Thread.run(Thread.java:745)
    

      如上面的报错方式,hql 被整理之后的sql 如上,是sql server 的样式

    而mysql 的样式 是 select * from [table]  where  1=1 limit m,n

    在找了自己的配置文件之后,发现我的hibernate配置有问题。其中参数:hibernate.dialect:org.hibernate.dialect.SQLServerDialect

    而之前我一直没有使用分页查询,所以一直没有发现这个问题。毕竟使用select * from 【table】是所有的关系型数据的基本查询语句,所以不会报错,但是分页就不同了。

    所以正确的配置,请参考对照表:

    RDBMS 方言
    DB2 org.hibernate.dialect.DB2Dialect
    DB2 AS/400 org.hibernate.dialect.DB2400Dialect
    DB2 OS390 org.hibernate.dialect.DB2390Dialect
    PostgreSQL org.hibernate.dialect.PostgreSQLDialect
    MySQL org.hibernate.dialect.MySQLDialect
    MySQL with InnoDB org.hibernate.dialect.MySQLInnoDBDialect
    MySQL with MyISAM org.hibernate.dialect.MySQLMyISAMDialect
    Oracle (any version) org.hibernate.dialect.OracleDialect
    Oracle 9i/10g org.hibernate.dialect.Oracle9Dialect
    Sybase org.hibernate.dialect.SybaseDialect
    Sybase Anywhere org.hibernate.dialect.SybaseAnywhereDialect
    Microsoft SQL Server org.hibernate.dialect.SQLServerDialect
    SAP DB org.hibernate.dialect.SAPDBDialect
    Informix org.hibernate.dialect.InformixDialect
    HypersonicSQL org.hibernate.dialect.HSQLDialect
    Ingres org.hibernate.dialect.IngresDialect
    Progress org.hibernate.dialect.ProgressDialect
    Mckoi SQL org.hibernate.dialect.MckoiDialect
    Interbase org.hibernate.dialect.InterbaseDialect
    Pointbase org.hibernate.dialect.PointbaseDialect
    FrontBase org.hibernate.dialect.FrontbaseDialect
    Firebird

    org.hibernate.dialect.FirebirdDialect

    org.hibernate.dialect.SQLServerDialect
  • 相关阅读:
    win 8升级win8.1的几个问题
    使用ghost硬盘对拷备份系统
    在odl中怎样实现rpc
    ASP.NET常见内置对象(一)
    [Xcode 实际操作]六、媒体与动画-(12)检测UIView动画的结束事件:反转动画并缩小至不可见状态
    [Xcode 实际操作]六、媒体与动画-(11)UIView视图卷曲动画的制作
    [Xcode 实际操作]六、媒体与动画-(10)UIView视图翻转动的画制作
    [Xcode 实际操作]六、媒体与动画-(9)使用CATransaction Push制作入场动画
    [Xcode 实际操作]六、媒体与动画-(8)使用CATransaction Reveal制作渐显动画
    [Xcode 实际操作]六、媒体与动画-(7)遍历系统提供的所有滤镜
  • 原文地址:https://www.cnblogs.com/roychenyi/p/5384470.html
Copyright © 2011-2022 走看看