gpt4 book ai didi

java - Hibernate ClassCastException IdentNode 无法转换为 DotNode

转载 作者:太空宇宙 更新时间:2023-11-04 14:56:57 25 4
gpt4 key购买 nike

我在使用 JPQL 执行简单的更新查询时遇到了 ClassCastException。

下面是异常跟踪:

Caused by: java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.IdentNode cannot be cast to org.hibernate.hql.internal.ast.tree.DotNode
at org.hibernate.hql.internal.ast.tree.AssignmentSpecification.<init>(AssignmentSpecification.java:71) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.ast.HqlSqlWalker.evaluateAssignment(HqlSqlWalker.java:1133) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.ast.HqlSqlWalker.evaluateAssignment(HqlSqlWalker.java:1127) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.assignment(HqlSqlBaseWalker.java:1042) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.setClause(HqlSqlBaseWalker.java:747) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:367) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:255) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1777) [hibernate-core-4.2.0.SP1.jar:4.2.0.SP1]
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291) [hibernate-entitymanager-4.2.0.SP1.jar:4.2.0.SP1]
at org.jboss.as.jpa.container.AbstractEntityManager.createQuery(AbstractEntityManager.java:425) [jboss-as-jpa-7.2.1.Final-redhat.jar:7.2.1.Final-redhat]

我正在执行的查询是将任务从工作池中移出:

public Boolean changeWorkpool(final TaskWorkpoolChangeRequest taskWorkpoolChangeRequest) {
final Query query = entityManager.createQuery("UPDATE Task SET workpoolId = :workpoolId"
+ " WHERE taskId= :taskId");
query.setParameter("workpoolId", taskWorkpoolChangeRequest.getWorkpoolId())
.setParameter("taskId", taskWorkpoolChangeRequest.getTaskId());
return BooleanUtils.toBoolean(query.executeUpdate());
}

有人可以透露一些有关此异常的原因吗?

提前致谢。

最佳答案

最近几天我遇到了同样的问题,我对 JPQL 做了一些挖掘,发现 JPQL 更新查询无法更新关系。

正如 https://docs.oracle.com/middleware/1212/toplink/OTLCG/queries.htm#OTLCG94000 中所述

update queries can only update attributes of the object or its embeddables, its relationships cannot be updated.

我注意到WorkpoolTask可能有关系。所以也许它导致了问题。

希望有帮助。

关于java - Hibernate ClassCastException IdentNode 无法转换为 DotNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23093681/

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