【问题标题】:No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode HQL节点没有数据类型:org.hibernate.hql.internal.ast.tree.IdentNode HQL
【发布时间】:2014-12-15 18:47:11
【问题描述】:

我有 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]);

每次运行都会出错

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

分类定义:

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"
    }
}

你可以参考我之前遇到的问题来了解我到底想做什么Quest 1Quest 2

【问题讨论】:

  • 查看分类定义会很有帮助

标签: java hibernate grails hql


【解决方案1】:

SQL 查询使用列名,而 HQL 查询使用类属性。您正在从分类中选择 artifact_id,但分类类没有名为“artifact_id”的属性。要修复它,请使用 HQL 中的类属性。

SELECT artifactId FROM Classification

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      我得到相同的错误:

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

      通过将from 大写并将c 作为别名添加到Contact 类来修复

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

      【讨论】:

        猜你喜欢
        • 2016-08-11
        • 2010-11-03
        • 1970-01-01
        • 2018-07-20
        • 2016-09-19
        • 2021-09-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多