> there are 2 tables and 2 ValueObjects. customers and orders.
>
[quoted text clipped - 20 lines]
> select * from customers c inner join order o on c.customerID =
> o.FK_customerID
of course i agree with method 3 (left outer join instead of inner
join).
> If you're looking to implement an object layer based upon objects
> representing customers and orders,
let's say i would need to list 100 customers with or without orders.
but my question is actually, wouldn't it be a performance loss when
first fetching all customers and afterwards fetching all orders for
each customer.
that would make for 100 customers 101 queries. one for the customers
table and 100 for each customer on orders table.
with method 3, there would be only 1 query. how would hibernate handle
this ? would it calculate the performance overhead and choose and
appropriate method ? btw, i'm very new to hibernate.
David Harper yazdi:
> > there are 2 tables and 2 ValueObjects. customers and orders.
> >
[quoted text clipped - 56 lines]
> David Harper
> Cambridge, England
David Harper - 26 Nov 2006 17:17 GMT
> of course i agree with method 3 (left outer join instead of inner
> join).
[quoted text clipped - 9 lines]
> that would make for 100 customers 101 queries. one for the customers
> table and 100 for each customer on orders table.
If your application really does need to list every (customer,order)
pair, then you are correct, a join between the two tables is the
quickest way to fetch all of the data, especially if there are a lot of
customers and/or orders.
There is one disadvantage, though: your application must now do more
work when processing the result set, if you wish to group the orders by
customer. For example, if you want to list all of customer #1's orders
first, then all of customer#2's orders, and so on, then you must (a)
specify customer ID as a column to sort in your SQL query, and (b) write
the loop which processes the result set in such a way that it can detect
when the customer ID changes, which signals that you are now reading a
row which relates to a different customer than the previous row.
I'm afraid that I have no idea how/whether Hibernate handles this
automatically, since I don't use Hibernate :-)
David Harper
Cambridge, England
mehmet.gunacti@gmail.com - 27 Nov 2006 18:10 GMT
thanks, your answer helped. :)
David Harper yazdi:
> > of course i agree with method 3 (left outer join instead of inner
> > join).
[quoted text clipped - 29 lines]
> David Harper
> Cambridge, England
Lionel - 29 Nov 2006 19:26 GMT
> of course i agree with method 3 (left outer join instead of inner
> join).
[quoted text clipped - 13 lines]
> this ? would it calculate the performance overhead and choose and
> appropriate method ? btw, i'm very new to hibernate.
Hibernate will do what you ask it to do ;)
3 possibilities:
1) Look for customers using JOIN fetch mode on orders: 1 query everything is
loaded
2) Look for custormers with a SELECT fetch mode on orders: 101 queries
3) use method 2) but add a batch size=100 on orders: 2 queries, the second
one being select * from orders where customerID=? or customerID=? or .... or
customerID=? (100 "or")
Do performance and memory tests to choose the best method.
It takes 2 seconds to switch between them with hibernate.