No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode HQL

JavaHibernateGrailsHql

Java Problem Overview


I have the HQL where I trying to get artifacts that have no classification (when active is 0)

artifacts = Artifact.findAll("FROM Artifact WHERE id NOT IN ( SELECT artifact_id FROM Classification WHERE active = 1) AND document_id = :docid",[docid:document.id], [max:limit, offset:startIndex]);
							

Whenever I run I get the error

java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode 
 \-[IDENT] IdentNode: 'artifact_id' {originalText=artifact_id}

Classificaiton definition:

class Classification {

    public static final String USER_DEFAULT = "USER"
    public static final String USER_SYSTEM = "SYSTEM"

    TaxonomyNode node
    String artifactId 
    Boolean active
    String createdBy
    String updatedBy
    Date dateCreated
    Date lastUpdated
   

    static constraints = {
        node nullable:false, blank:false
        artifactId nullable:false, blank:false, unique: ['node']
        active nullable: false, blank: false
        createdBy nullable:false, blank:false
        updatedBy nullable:false, blank:false
    }

    static mapping = {
        id generator:'sequence', params:[sequence:'classification_seq']
        artifactId index: 'classify_by_artifact_node'
        node index: 'classify_by_artifact_node'
        active defaultValue: "1"
    }
}

You can refer to previous problems I faced to understand what exactly I am trying to do Quest 1 and Quest 2

Java Solutions


Solution 1 - Java

SQL queries use column names while HQL queries use Class properties. You're selecting artifact_id from Classification but the Classification class has no property named 'artifact_id'. To fix it, use the class property in your HQL.

SELECT artifactId FROM Classification

Solution 2 - Java

It occurs sometimes when keyword 'new' is missed for your DTO (DATA TRANSFER OBJECT).

Solution 3 - Java

I get identical error when I've :

 @NamedQuery(name="Contact.findAll",query="SELECT c from Contact")

it fixed by uppercasing the from and adding the c as alias to Contact class

@NamedQuery(name="Contact.findAll",query="SELECT c FROM Contact c")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionkrs8785View Question on Stackoverflow
Solution 1 - JavaVimmView Answer on Stackoverflow
Solution 2 - JavaTejas PawarView Answer on Stackoverflow
Solution 3 - JavaBoussadjra BrahimView Answer on Stackoverflow