您应该阅读以下常见问题解答:对于为集合启用了外部联接获取的查询,Hibernate不会返回不同的结果(即使我使用了distinct关键字)?
如您注意到的那样,当您指定急切加载时,结果集包含7 * 3行,但实际上您的内存中只有7个productTypes对象(每个对象有2个额外的引用)。
要执行您想要的 *** 作,您可以添加(请注意基础sql查询未更改):
SetResultTransformer(new DistinctRootEntityResultTransformer())
def results = ProductType.withCriteria { fetchMode("attributes", org.hibernate.FetchMode.EAGER) SetResultTransformer(new DistinctRootEntityResultTransformer())}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)