Grails - GORM生成错误的查询语法

时间:2015-01-13 11:48:08

标签: hibernate grails gorm

嗨我有Hibernate domain喜欢

class Parent {
    ....
    @javax.persistence.OneToMany(mappedBy = "parent", cascade = {javax.persistence.CascadeType.ALL}, fetch = javax.persistence.FetchType.LAZY)
    @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
    @org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN, org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    private java.util.Set<Child> childs;
    ...
}

class Child {
    ...
    @javax.persistence.ManyToOne
    @javax.persistence.JoinColumn(name = "PARENT_ID", nullable = false)
    private Parent parent;
    ...
}

尝试编写gorm查询

def criteria = Parent.createCriteria();
List result = criteria.list() {
   //fetchMode "childs", FetchMode.JOIN
   childs {
       eq("childProperty",testValue)
   }
}

我能够获得预期的结果,但在后台,sql就像

select this_....... from parent this_
inner join child child_ on this_.parent_id = child_.parent_id
left outer join child child_ on this_.parent_id = child_.parent_id // this line is buggy
where child_.childProperty = (?)

我担心的是第二个left outer join实际上并不需要结果。

0 个答案:

没有答案