开发者

HQL Join Fetch question: aliasing association

Given I have an object A with a collection B and I want to get A with all B that fit a certain criteria

"from A a left join fetch a.bs c where a.id = ? and c.id = ?"

The above certainly won't work so there must be another fetch after I alias c so would this be correct

"from A a left join fetch a.bs c join fetch c.id = ? where a.id = 开发者_运维技巧?"


Second query won't work due to invalid syntax. First one will work, but (I'm guessing here) not the way you want it to.

I take it you want to select some As and populate their collection of Bs only with Bs satisfying specific criteria? You can't. Entire collection of owned Bs will be fetched for each A instance (putting aside technical implications dealing with batch sizes). This is done in order to prevent accidental orphaning of Bs should you choose to save your A back with incomplete collection of Bs.

If I misunderstood and that's not what you meant, please clarify your question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜