简体   繁体   中英

Hibernate - second level association

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 is 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM