Files

36 lines
1.8 KiB
Plaintext

## findWithCategory(7) -> association fills product.category from joined columns
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id , c.id AS c_id, c.name AS c_name FROM product p JOIN category c ON c.id = p.category_id WHERE p.id = ?
==> Parameters: 7(Long)
<== Total: 1
result: Product[7, Product 07, 27.50, stock=9, active=true, categoryId=2, category=Gadgets]
## allWithProductsJoin() -> one statement, nested result map folds rows into objects
==> Preparing: SELECT c.id AS c_id, c.name AS c_name, p.id AS p_id, p.name AS p_name, p.price AS p_price, p.stock AS p_stock FROM category c LEFT JOIN product p ON p.category_id = c.id AND p.active = TRUE ORDER BY c.id, p.id
==> Parameters:
<== Total: 41
Category[1, Books, products=14]
Category[2, Gadgets, products=13]
Category[3, Kitchen, products=14]
statements executed: 1
## allWithProductsNestedSelect() -> one query, then one more per category
==> Preparing: SELECT id, name FROM category ORDER BY id
==> Parameters:
====> Preparing: SELECT id, name, price, stock, active, category_id FROM product WHERE category_id = ? AND active = TRUE ORDER BY id
====> Parameters: 1(Long)
<==== Total: 14
====> Preparing: SELECT id, name, price, stock, active, category_id FROM product WHERE category_id = ? AND active = TRUE ORDER BY id
====> Parameters: 2(Long)
<==== Total: 13
====> Preparing: SELECT id, name, price, stock, active, category_id FROM product WHERE category_id = ? AND active = TRUE ORDER BY id
====> Parameters: 3(Long)
<==== Total: 14
<== Total: 3
Category[1, Books, products=14]
Category[2, Gadgets, products=13]
Category[3, Kitchen, products=14]
statements executed: 4
## both strategies return the same product ids per category
identical: true