eager-loading queries with GORM/Hibernate

懵懂的女人 提交于 2019-12-04 14:33:33
manji

you should read this faq: Hibernate does not return distinct results for a query with outer join fetching enabled for a collection (even if I use the distinct keyword)?

When you specify eager loading, the resultset contains, as you noticed, 7*3 rows but in fact you only have 7 productTypes objects in memory (& 2 extra references for each).
To do what you want, you can add (be aware that the underlying sql query did not change):

SetResultTransformer(new DistinctRootEntityResultTransformer())

def results = ProductType.withCriteria {
    fetchMode("attributes", org.hibernate.FetchMode.EAGER)
    SetResultTransformer(new DistinctRootEntityResultTransformer())
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!