Thursday, August 8, 2013

Fetch Type vs Fetch Mode in Hibernate

Fetch Type vs Fetch Mode in Hibernate

Fetch type (lazy/eager) tells when Hibernate fetches the association, whether in advance when it fetches the entity (eager), or whether it waits for the code to ask for the association (lazy).

Fetch mode (select/join) refers to how Hibernate will fetch the association, i.e. does it use an extra SELECT statement, or does it use a join.

Some combinations of these make no sense, e.g. lazy+join. If you use lazy fetching, then SELECT fetch mode is the only one that you can do.If you use eager fetch, then you can choose to use either fetch mode.