没有节点的数据类型:org.hibernate.hql.internal.ast.tree.IdentNode HQL

krs*_*785 35 java grails hibernate hql

我有HQL,我试图获取没有分类的工件(当活动为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]);
Run Code Online (Sandbox Code Playgroud)

每当我跑,我得到错误

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

分类定义:

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"
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以参考我之前遇到的问题,以了解我究竟想要做什么Quest 1Quest 2

小智 73

SQL查询使用列名,而HQL查询使用Class属性.您正在从Classification中选择artifact_id,但Classification类没有名为'artifact_id'的属性.要修复它,请在HQL中使用class属性.

SELECT artifactId FROM Classification
Run Code Online (Sandbox Code Playgroud)


小智 25

当您的 DTO(数据传输对象)缺少关键字“新”时,有时会发生这种情况。