fetch设置为lazy,查询Parent对象的时候,默认只有Parent的内容,并不包含child的信息,这样可以避免n+1问题。
但又想查询parent时把children得到,就可以用fetch。
fetch主动将child得到并set到children列表中。
HQL语句:from Parent p left join fetch p.children
fetch设置为lazy,查询Parent对象的时候,默认只有Parent的内容,并不包含child的信息,这样可以避免n+1问题。
但又想查询parent时把children得到,就可以用fetch。
fetch主动将child得到并set到children列表中。
HQL语句:from Parent p left join fetch p.children