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

3

65

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

Gyniatrics answered 20/10, 2014 at 17:33 Comment(1)
It would be helpful to see Classification definitionCilia
V
104

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
Viyella answered 20/10, 2014 at 19:4 Comment(1)
If you give any alias to the table/entity then that needs to be used. For examlple SELECT c.artifactId FROM Classification cEstray
F
36

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

Fricative answered 12/3, 2020 at 16:15 Comment(0)
A
1

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")
Acquit answered 12/9, 2021 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.