0

Please could someone help me understand the concept of - "Eager fetching with Joins" in Hibernate with a simple example query and table depicting the result of the query. I have searched the net but unable to get an explanation with a good example. Please kindly help and guide me.

sid
  • 129
  • 3
  • 11

1 Answers1

0

Eager fetching brings back joined table data immediately in the initial fetch of the object, rather than waiting until it's requested explicitly by the application.

From a SQL perspective, it might be more efficient, assuming you always want to use the eagerly fetched data. In general, it's often better to wait until the application requires the data, at which point Hibernate makes a new query to fetch the data.

It's really the same idea as lazy-initializing application constructs - don't create that connection/socket/open a resource/whatever until you actually need it, if you need it.

Eager fetching can also be very non-scaleable, if this is a parent-child relationship where the child has 1000s/10000s/1000000s of child objects. This is probably the place where most hibernate performance problems originate, the solution is to fetch children manually - not as convenient, but your application will be happy.

[Sorry, don't have an example close at hand, but thought I could explain it well enough without.]

Scott Sosna
  • 1,443
  • 1
  • 8
  • 8