Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with this HQL? "No data type for node"

session.createQuery("Select attribute from GoodsSection tgs " +     "join gs.ascendants ags join ags.attributes attribute " +     "where attribute.outerId = :outerId and tgs = :section ") .setString("outerId", pOuterId) .setEntity("section", section) .setMaxResults(1) .uniqueResult(); 

Looks fine to me, but the result is

java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.IdentNode   \-[IDENT] IdentNode: 'attribute' {originalText=attribute}      at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:145)     at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:705)     at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:529)     at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645)     at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)     at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229) 

Why? What's wrong?

like image 864
alamar Avatar asked Jun 18 '09 12:06

alamar


People also ask

What is the difference between JPQL and HQL?

The Hibernate Query Language (HQL) and Java Persistence Query Language (JPQL) are both object model focused query languages similar in nature to SQL. JPQL is a heavily-inspired-by subset of HQL. A JPQL query is always a valid HQL query, the reverse is not true however.

What is HQL?

A person may not purchase, rent, or receive a handgun after October 1, 2013 unless they possess a valid Handgun Qualification License (HQL) issued by the Maryland State Police or qualify for exemption status.

Is HQL type safe?

Both HQL and JPQL are non-type-safe ways to perform query operations. Criteria queries offer a type-safe approach to querying.

Is HQL like SQL?

HQL or Hibernate Query Language is the object-oriented query language of Hibernate Framework. HQL is very similar to SQL except that we use Objects instead of table names, that makes it more close to object oriented programming.


1 Answers

You haven't defined the "gs" alias. You only have "ags" and "tgs".

like image 70
skaffman Avatar answered Oct 22 '22 20:10

skaffman