Tasyp
Tasyp

Reputation: 21

JPQL Operator returns a java.lang.IllegalStateException - No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode

I have been all around Stackoverflow and tested a number of suggestions but to no success.

I have this SELECT OPERATOR('ToChar', a.created,'MM-YYYY') AS _month, COUNT(a) FROM Account AS a GROUP BY _month query that returns an error that, to my disappointment, I have not been able to solve.

The error is:

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''

Anyone who can help me, I would very much appreciate it. Thank you.

Upvotes: 1

Views: 189

Answers (1)

Tasyp
Tasyp

Reputation: 21

In case someone else ever runs into a similar problem. I ended up using a different JPQL query to achieve my goal.

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)

Then I return a List<Object[]>.

The full method is

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();
        }
    }

I don't know if this is the best way to do it but it's certainly what worked for me.

Upvotes: 1

Related Questions