这说明了为什么对fetch-joined集合添加限制会导致集合未初始化( 请注意 ,没有限制的同一查询会为集合急切地获取数据):
“如果表A和B之间的关系为1:n,并且对B添加了限制,并且希望能尽快获取它,那么问题是当您要从A导航到B时会发生什么。只查看B中符合限制条件的数据,还是应该查看与A相关的所有B?”
在这里看到更多…
但是,使用HQL代替标准,部分获取出价集合
List<Item> items = session.createQuery( "from Item i left join fetch i.bids b where b.amount > :amount") .setParameter("amount", 100) .list();在我看来,这是不一致的,但这就是它的工作原理
顺便说一句,如果您需要的是父母及其所有子女的清单,而仅是其子女都满足一定限制的父母,那么您可以使用此清单
List<Item> items = session.createQuery( "from Item i left join fetch i.bids b " + "where not exists (from Bid b where b.item = i and b.amount <= :amount)") .setParameter("amount", 100) .list();


