简体   繁体   English

休眠-二级关联

[英]Hibernate - second level association

Let's say I have table foo, table bar, and table zoo. 假设我有表foo,表栏和表Zoo。 foo has a member bar and there is a one to one relationship between them. foo有一个成员栏,并且它们之间存在一对一的关系。 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. 读取bar时,列表不会自动初始化(即是懒惰的)。我想使用hql获取在bar中初始化了Zoo的foo对象的列表。

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. 这显然引发了异常,我知道这是因为返回的所有者是Foo而不是Bar。 Nonetheless I need Foo and not Bar and I need zoo to be initialized. 尽管如此,我需要Foo而不是Bar,并且我需要初始化Zoo。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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