gpt4 book ai didi

java - 使用setParameter或setParametrList删除数据HQL奇怪

转载 作者:行者123 更新时间:2023-12-02 07:38:33 25 4
gpt4 key购买 nike

我有一个简单的表,并尝试通过 ids 数组删除数据。

Integer[] arrayIDs = {1,2,3}; //External ids as parameteres
Query deleteItemsQuery = session.createQuery("DELETE Items WHERE id IN (:idsDeletingItems)"); //(in this row exception)
deleteItemsQuery.setParameterList("idsDeletingItems", arrayIDs);
deleteItemsQuery.executeUpdate();

我的应用程序抛出异常

我还尝试删除 1 个参数。例如

Query deleteItemsQuery = session.createQuery("DELETE Items WHERE id = '1'");
deleteItemsQuery.executeUpdate();

使用该变体没有问题。

但是当我下一步做时,我也有异常(exception)

Integer myID = 1;
Query deleteItemsQuery = session.createQuery("DELETE Items WHERE id = (:myID)");
deleteItemsQuery.setParameter("myID", myID);
deleteItemsQuery.executeUpdate();

我使用这个方言org.hibernate.dialect.Oracle10gDialect。有什么想法吗?

异常

exception 

javax.servlet.ServletException: java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:295)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:113)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
com.epam.testapp.presentation.filter.CharsetFilter.doFilter(CharsetFilter.java:44)
com.epam.testapp.presentation.filter.CommandFilter.doFilter(CommandFilter.java:58)


root cause

java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I
org.hibernate.hql.internal.ast.HqlSqlWalker.generateNamedParameter(HqlSqlWalker.java:956)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.parameter(HqlSqlBaseWalker.java:4821)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1347)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4297)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3772)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1947)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:794)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.deleteStatement(HqlSqlBaseWalker.java:443)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:263)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:219)
org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:197)
org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1736)
com.epam.testapp.database.NewsHibernateDAO.remove(NewsHibernateDAO.java:89)
com.epam.testapp.presentation.action.NewsAction.delete(NewsAction.java:150)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:113)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

最佳答案

就这样吧

Integer myID = 1;
Query deleteItemsQuery = session.createQuery("DELETE Items WHERE id =:myID");
deleteItemsQuery.setParameter("myID", myID);
deleteItemsQuery.executeUpdate();

并确保“:”和“myID”之间没有空格,否则会出现另一个错误。

希望有帮助;-)

关于java - 使用setParameter或setParametrList删除数据HQL奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11877675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com