gpt4 book ai didi

java - JPQL 运算符返回 java.lang.IllegalStateException - 节点 : org. hibernate.hql.internal.ast.tree.MethodNode 没有数据类型

转载 作者:行者123 更新时间:2023-12-02 08:49:56 25 4
gpt4 key购买 nike

我一直在 Stackoverflow 上工作,并测试了一些建议,但没有成功。

我有这个 SELECT OPERATOR('ToChar', a.created,'MM-YYYY') AS _month, COUNT(a) FROM Account AS a GROUP BY _month 查询,该查询返回以下错误,令我失望的是,我一直没能解决。

错误是:

java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode 
\-[METHOD_CALL] MethodNode: '('
+-[METHOD_NAME] IdentNode: 'OPERATOR' {originalText=OPERATOR}
\-[EXPR_LIST] SqlNode: 'exprList'
+-[QUOTED_STRING] LiteralNode: ''ToChar''
+-[DOT] DotNode: 'account0_.created' {propertyName=created,dereferenceType=PRIMITIVE,getPropertyPath=created,path=a.created,tableAlias=account0_,className=com.eoh.permasys.entities.Account,classAlias=a}
| +-[ALIAS_REF] IdentNode: 'account0_.id' {alias=a, className=com.eoh.permasys.entities.Account, tableAlias=account0_}
| \-[IDENT] IdentNode: 'created' {originalText=created}
\-[QUOTED_STRING] LiteralNode: ''MM-YYYY''

如果有人能帮助我,我将不胜感激。谢谢。

最佳答案

以防其他人遇到类似的问题。我最终使用不同的 JPQL 查询来实现我的目标。

SELECT EXTRACT(MONTH FROM a.created), EXTRACT(YEAR FROM a.created), COUNT(a) FROM Account AS a GROUP BY EXTRACT(MONTH FROM a.created), EXTRACT(YEAR FROM a.created)

然后我返回 List<Object[]>

完整的方法是

public List<Object[]> countAccountsCreatedPerMonth() {
EntityManager em = getEntityManager();
try {
Query q = em.createQuery("SELECT EXTRACT(MONTH FROM a.created), EXTRACT(YEAR FROM a.created), COUNT(a) FROM Account AS a GROUP BY EXTRACT(MONTH FROM a.created), EXTRACT(YEAR FROM a.created)");
return q.getResultList();
} finally {
em.close();
}
}

我不知道这是否是最好的方法,但这肯定对我有用。

关于java - JPQL 运算符返回 java.lang.IllegalStateException - 节点 : org. hibernate.hql.internal.ast.tree.MethodNode 没有数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60845097/

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