简体   繁体   English

org.hibernate.exception.GenericJDBCException:无法执行查询

[英]org.hibernate.exception.GenericJDBCException: could not execute query

Upon trying to convert strings to dates for comparison, Hibernate throws 尝试将字符串转换为日期进行比较时,Hibernate引发

org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:无法执行查询

full stacktrace: 完整的堆栈跟踪:

    javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255)
    at com.callsystem.business.callFinder.findCustom(callFinder.java:215)
    at com.callsystem.UI.searchCustomerCallsView$2.buttonClick(searchCustomerCallsView.java:99)
    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.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1008)
    at com.vaadin.ui.Button.fireClick(Button.java:377)
    at com.vaadin.ui.Button$1.click(Button.java:54)
    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.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:158)
    at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
    at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:408)
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:273)
    at com.vaadin.server.communication.PushHandler$2.run(PushHandler.java:149)
    at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:243)
    at com.vaadin.server.communication.PushHandler.onMessage(PushHandler.java:503)
    at com.vaadin.server.communication.PushAtmosphereHandler.onMessage(PushAtmosphereHandler.java:88)
    at com.vaadin.server.communication.PushAtmosphereHandler.onRequest(PushAtmosphereHandler.java:78)
    at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:199)
    at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:107)
    at org.atmosphere.container.TomcatWebSocketUtil.doService(TomcatWebSocketUtil.java:154)
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.service(Tomcat7Servlet30SupportWithWebSocket.java:62)
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2075)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:571)
    at org.atmosphere.websocket.DefaultWebSocketProcessor$3.run(DefaultWebSocketProcessor.java:333)
    at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:328)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:425)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatchReader(DefaultWebSocketProcessor.java:795)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:527)
    at org.atmosphere.container.TomcatWebSocketHandler.onTextData(TomcatWebSocketHandler.java:104)
    at org.apache.catalina.websocket.StreamInbound.doOnTextData(StreamInbound.java:190)
    at org.apache.catalina.websocket.StreamInbound.onData(StreamInbound.java:138)
    at org.apache.coyote.http11.upgrade.UpgradeProcessor.upgradeDispatch(UpgradeProcessor.java:88)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:599)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2545)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
    ... 46 more
    Caused by: java.sql.SQLException: No database selected
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2834)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2313)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2542)
    ... 54 more

HQl statement used: 使用的HQl语句:

 String hql = "FROM CallSystemCustomerCallEntity WHERE str(refno) LIKE :refNo AND "
                    + "customer LIKE :customer AND site LIKE :site AND faults LIKE :faults "
                    + "AND detailedfaults LIKE :dfaults AND owner LIKE :owner "
                    + "AND date(to_date(date, 'dd-MM-yy')) >= :sDate AND "
                    + "date(to_date(date, 'dd-MM-yy')) <= :eDate ORDER BY refno asc";

Creating the query: 创建查询:

List<CallSystemCustomerCallEntity> c = em.createQuery(hql).
                    setParameter("refNo", "%" + refNo + "%").setParameter("customer", "%" + customer + "%")
                    .setParameter("site", "%" + site + "%").setParameter("faults", "%" + faults + "%")
                    .setParameter("dfaults", "%" + dfaults + "%").setParameter("owner", "%" + owner + "%")
                    .setParameter("sDate",date1).setParameter("eDate", date2).getResultList();

The database in question is a MySQL database and all other queries I try work, however inclusion of the date paremeters cause this exception to be thrown. 有问题的数据库是一个MySQL数据库,我尝试的所有其他查询都可以工作,但是包含日期参数会引发此异常。

Just guessing : you call to_date function but as it is not a hql function it is sent as-is to the database. 只是猜测:您调用to_date函数,但由于它不是hql函数,因此按原样发送到数据库。 Mysql receive a sql request with a "to_date" function, but mysql don't have to_date function (it's Oracle specific, you have to use STR_TO_DATE). Mysql接收带有“ to_date”函数的sql请求,但是mysql没有to_date函数(它是Oracle特定的,您必须使用STR_TO_DATE)。 So mysql search the function as a custom function in the current database but complain that no database have been selected... 因此mysql在当前数据库中搜索该函数作为自定义函数,但抱怨没有选择数据库。

So, remove to_date (and the date()) and try something with STR_TO_DATE (see https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html ). 因此,删除to_date(和date())并尝试使用STR_TO_DATE(请参见https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html )。

Edit: and use debug log from hibernate to see the sql sent to the database => the stacktrace show that the exception come from the database, with the sql you can test the query against the database : it's helpful for debugging 编辑:并使用来自休眠的调试日志来查看发送到数据库的sql => stacktrace显示异常来自数据库,使用sql可以针对数据库测试查询:这对调试很有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ested异常是org.hibernate.exception.GenericJDBCException:无法执行查询 - ested exception is org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:无法执行查询]的根本原因 - org.hibernate.exception.GenericJDBCException: could not execute query] with root cause org.hibernate.exception.GenericJDBCException:无法执行查询 - org.hibernate.exception.GenericJDBCException: could not execute query substr错误:org.hibernate.exception.GenericJDBCException:无法执行查询 - substr error: org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:无法在hibernate中执行语句 - org.hibernate.exception.GenericJDBCException: could not execute statement in hibernate org.hibernate.exception.GenericJDBCException:无法执行语句 - org.hibernate.exception.GenericJDBCException: could not execute statement 更新查询的 JPA @Query 注释(oracle sql 开发人员)--org.hibernate.exception.GenericJDBCException:无法执行查询 - JPA @Query annotation for update query (oracle sql developer) -- org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:执行此代码时无法执行查询异常 - org.hibernate.exception.GenericJDBCException: could not execute query Exception while executing this code org.hibernate.exception.GenericJDBCException:无法插入: - org.hibernate.exception.GenericJDBCException: could not insert: 谁能告诉我为什么会这样“ org.hibernate.exception.GenericJDBCException:无法执行查询”? - Can anyone tell me why this is happening “org.hibernate.exception.GenericJDBCException: could not execute query”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM