开发者

When using setFetchMode in Hiberate criteria how do I set a restriction on the oneToMany table

开发者 https://www.devze.com 2023-02-22 08:22 出处:网络
I\'m struggling to create a Hibernate criteria query that uses setFetchMode(... SELECT) and places a restriction on the returned child records. If I use a creteAlias as recommended it produces an inne

I'm struggling to create a Hibernate criteria query that uses setFetchMode(... SELECT) and places a restriction on the returned child records. If I use a creteAlias as recommended it produces an inner join thereby making accurate pagination all but impossible.

The code would be like:-

Criteria criteria = this.getSession().createCriteria(Mother.class);
criteria.addOrder(Order.asc("titl开发者_运维知识库e"))
// .createAlias("children", "childrenAlias") had to remove
.add(Restrictions.eq("childAge", "5")) // how do I reference childAge?
.setMaxResults(details.getMaxRows())
.setFirstResult(details.getStart())
.setFetchMode("children", FetchMode.SELECT);


God knows where I was at when I posted this. Thought I'd post the answer to tidy up.

The code I was missing was the following:-

Criterion child = Restrictions.eq("childAlias.childName", "Albert");
criteria.createAlias("children", "childAlias", CriteriaSpecification.INNER_JOIN);
criteria.add(child);
0

精彩评论

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