grails分离标准模糊列

时间:2014-01-10 15:37:26

标签: hibernate grails ambiguous

在grails中使用DetachedCriteria过滤时,我们得到一个ORA-00918:列模糊定义的错误,而域类有多个同一类的集合。

我们的域名看起来像这样:

class Document {
    ...
    static hasMany = [primaries : Node, secondaries: Node]

    static mapping = {
        primaries joinTable: [name: 'doc_primary',
            key: 'doc_id',
            column: 'node_id']
        secondaries joinTable: [name: 'doc_secondary',
            key: 'doc_id',
            column: 'node_id']
    }
}

在我们的控制器代码中,我们设置了一个DetachedCriteria对象,并在用户想要按Document对象的两个属性进行过滤时运行查询:

criteria - new DetachedCriteria(Document).build {
    def primaryIds = [1,2,3]
    def secondaryIds = [4,5,6]

    primaries {
        'in'('id', primaryIds)
    }

    secondaries {
        'in'('id', secondaryIds)
    }

}

def filteredDocs = criteria.list()

看起来hibernate会为此查询生成以下SQL,并且会使列模糊定义错误(请参阅重复的 doc1_8 _ ):

SELECT *
  FROM (  SELECT this_.id AS id8_2_,
                  ...
                  primaries4_.doc_id AS doc1_8_,
                  secondaries6_.doc_id AS doc1_8_
                  ...
          FROM DOCUMENT this_
              INNER JOIN doc_primary primaries4_
                  ON this_.id = primaries4_.doc_id
              INNER JOIN doc_secondary secondaries6_
                  ON this_.id = secondaries6_.doc_id

我们认为我们需要设置别名或其他内容,但看起来当前版本的grails中DetachedCriteria不支持别名。还有其他我们缺少的东西吗?

0 个答案:

没有答案