A join combines rows from related tables so an application can retrieve the portion of an object network it expects to navigate with fewer database requests. Planning matters: joining too little causes piecemeal lazy loading, while joining too much wastes memory and can produce huge result sets. section 1.2.5
Use joins with these operational tradeoffs:
- Join to-one associations efficiently; one query can retrieve an item, seller, address, and city without multiplying rows. section 12.2.2
- Limit joined tables with fetch-depth configuration; beyond the limit, Hibernate continues eager loading through additional SELECT statements. section 12.2.2
- Avoid eagerly joining multiple collections together because their rows can multiply into a Cartesian product. section 12.2.2
Filtering users through joined bids
Querydsl expresses the relationship and its join condition directly: queryFactory.selectFrom(QUser.user).innerJoin(QUser.user.bids, QBid.bid).on(QBid.bid.amount.eq(new BigDecimal("120.00"))).fetch(); Hibernate generates an INNER JOIN between User and Bid, restricting joined bids by amount. section 19.3.4
item = em.find(Item.class, ITEM_ID); // select i.*, u.* // from ITEM i // left outer join USERS u on u.ID = i.SELLER_ID // where i.ID = ?
Inspect the SQL shape of an ORM join that retrieves an Item and its seller in one SELECT. section 12.2.2















