开发者

Hibernate - second level association

开发者 https://www.devze.com 2023-01-21 14:48 出处:网络
Let\'s say I have table foo, table bar, and table zoo. foo has a member bar and there is a one to one relationship between them.

Let's say I have table foo, table bar, and table zoo. foo has a member bar and there is a one to one relationship between them. bar has a list and there is a one to many relationship between them.

the list is not initialized automatically when bar is read (ie it is lazy) Using hql I would like to get a list of the foo objects with zoo initialized in bar.

so something on the lines of:

select f from Foo f
left join fetch f.bar.zoo

this obviously throws an exception and I get that it's because the owner being returned i开发者_运维问答s Foo and not Bar. Nonetheless I need Foo and not Bar and I need zoo to be initialized. Is there a way to do this in one query?

Thanks Jill


The following should work:

FROM Foo f
  LEFT JOIN FETCH f.bar b
  LEFT JOIN FETCH b.zoos
0

精彩评论

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

关注公众号