嗨我有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
实际上并不需要结果。