使用以下命令执行hql查询时出现错误
Query query = session.createQuery(q);
我的查询是
select AU_USER from AU_TABLE where AU_ID in(010012025160151756912703600209,010012025160150254316794700103)
堆栈跟踪为
2018-07-06 11:25:05 ERROR ErrorCounter:54 - line 1:74: unexpected token: 912703600209 2018-07-06 11:25:05 ERROR ErrorCounter:50 - line 1:74: unexpected token: 912703600209 line 1:74: unexpected token: 912703600209 at org.hibernate.hql.internal.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:646) at org.hibernate.hql.internal.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2595) at org.hibernate.hql.internal.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2456) at org.hibernate.hql.internal.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2420) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2336) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2301) at org.hibernate.hql.internal.antlr.HqlBaseParser.expression(HqlBaseParser.java:2011) at org.hibernate.hql.internal.antlr.HqlBaseParser.compoundExpr(HqlBaseParser.java:3062) at org.hibernate.hql.internal.antlr.HqlBaseParser.inList(HqlBaseParser.java:2884) at org.hibernate.hql.internal.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2730) at org.hibernate.hql.internal.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2456) at org.hibernate.hql.internal.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2420) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2336) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2301) at org.hibernate.hql.internal.antlr.HqlBaseParser.expression(HqlBaseParser.java:2011) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalExpression(HqlBaseParser.java:1787) at org.hibernate.hql.internal.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:452) at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:707) at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:294) at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:157) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:267) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:181) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:137) at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:105) at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:80) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778) at com.adeptia.dao.MigrationDao.getIndigoUsersBySchemaIds(MigrationDao.java:1096) at com.adeptia.dao.MigrationDao.main(MigrationDao.java:1120) 2018-07-06 11:25:05 WARN HqlParser:259 - HHH000203: processEqualityExpression() : No expression to process! 2018-07-06 11:25:05 ERROR ErrorCounter:54 - line 1:109: unexpected token: 94700103 2018-07-06 11:25:05 ERROR ErrorCounter:50 - line 1:109: unexpected token: 94700103 line 1:109: unexpected token: 94700103 at org.hibernate.hql.internal.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:646) at org.hibernate.hql.internal.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2595) at org.hibernate.hql.internal.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2456) at org.hibernate.hql.internal.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2420) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2336) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2301) at org.hibernate.hql.internal.antlr.HqlBaseParser.expression(HqlBaseParser.java:2011) at org.hibernate.hql.internal.antlr.HqlBaseParser.compoundExpr(HqlBaseParser.java:3069) at org.hibernate.hql.internal.antlr.HqlBaseParser.inList(HqlBaseParser.java:2884) at org.hibernate.hql.internal.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2730) at org.hibernate.hql.internal.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2456) at org.hibernate.hql.internal.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2420) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2336) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2301) at org.hibernate.hql.internal.antlr.HqlBaseParser.expression(HqlBaseParser.java:2011) at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalExpression(HqlBaseParser.java:1787) at org.hibernate.hql.internal.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:452) at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:707) at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:294) at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:157) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:267) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:181) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:137) at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:105) at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:80) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778) at com.adeptia.dao.MigrationDao.getIndigoUsersBySchemaIds(MigrationDao.java:1096) at com.adeptia.dao.MigrationDao.main(MigrationDao.java:1120) 2018-07-06 11:25:05 WARN HqlParser:259 - HHH000203: processEqualityExpression() : No expression to process!
答案 0 :(得分:0)
如果您要像这样执行sql查询:
#include <MsgBoxConstants.au3>
; Press Esc to terminate script, Pause/Break to "pause"
Global $g_bPaused = False
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{SPACE}", "ShowMessage") ; Shift-Alt-d
While 1
Sleep(100)
WEnd
Func TogglePause()
$g_bPaused = Not $g_bPaused
While $g_bPaused
Sleep(100)
ToolTip('Script is "Paused"', 0, 0)
WEnd
ToolTip("")
EndFunc ;==>TogglePause
Func Terminate()`enter code here`
Exit
EndFunc ;==>Terminate
Func ShowMessage()
Send("{SPACE}p{SPACE}")
EndFunc ;==>ShowMessage
然后尝试以下代码:
String q="select AU_USER from AU_TABLE where AU_ID in(010012025160151756912703600209,010012025160150254316794700103)";
希望您的问题得到解决。如果仍然遇到问题,请再次发布查询。
答案 1 :(得分:0)
使用createSQLQuery代替createQuery解决了问题
Query query = session.createSQLQuery(q);