开发者

HIbernate FetchMode Join

开发者 https://www.devze.com 2022-12-21 02:03 出处:网络
I have a Parent class with a List of children. I would like to load the Parent by something other than the id e.g. by name...I am using criteria.setFetchMode(\"children\",FetchMode.JOIN);

I have a Parent class with a List of children. I would like to load the Parent by something other than the id e.g. by name...I am using criteria.setFetchMode("children",FetchMode.JOIN); and criteria.add(Restrictions.eq("name", name)) to eagerly load all the data for the parent with a unique name. Problem is I get back thousands of results al开发者_C百科l with the same name...How do I get round this.


Try criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).

This applies a transformation after executing the query which combines the rows for the same root, which is commonly desired on an outer join with Hibernate Criteria.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号