Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to confirm lazy loading is working

I am learning hibernate and i am using the debugger to understand how hibernate fetches objects. I have enabled lazy loading in my XML and i use create a query to get an object. This object has a Set associated with it.

When i look at the variable values in my debugger it seems to be completely loading the object graph, ie not lazily fetching the set and its properties. I can think of several reasons why this might be the case.

1) something is wrong with my xml / config and i have eager fetching enabled. I'm not sure this is the case, everything is at its defaults which is to lazy fetch.

2) The way the IDE debugger works is that is causes hibernate to trigger the lazy loading when i look at them.

3) Hibernate is fetching the entire object graph from the 2nd level cache. Ive tried to disable this but this seems to have no effect

Any other ideas?

like image 953
Luke De Feo Avatar asked Oct 19 '25 15:10

Luke De Feo


1 Answers

Debugging (showing the lazy fields, to be precise) triggers the lazy loading already. Get the entity, detach it and access your lazy field. Should throw some sort of exception if lazy loading works.

If you really want to know how hibernate does it, have a look at the sources.

like image 144
atamanroman Avatar answered Oct 22 '25 04:10

atamanroman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!