Eko Kurniawan Khannedy
Eko Kurniawan Khannedy

Reputation: 710

Are you able to prove the Hibernate Lazy-Loading?

I just want to ask, how to prove that hibernate is doing lazy loading . I have code like this :

enter image description here

And I try to test lazy loading in hibernate (jpa) with this code :

enter image description here

Actually, I don't wont to load "alamat" property, because that's a TEXT. But when I try to debug the code, I get the output trace like this :

enter image description here

Hibernate is still select alamat column, and in the debug veriable, I found that Hibernate is really load alamat column :

enter image description here

Upvotes: 0

Views: 2525

Answers (2)

Codo
Codo

Reputation: 78855

The Hibernate manual notes:

To enable property level lazy fetching, your classes have to be instrumented: bytecode is added to the original class to enable such feature, please refer to the Hibernate reference documentation. If your classes are not instrumented, property level lazy loading is silently ignored.

How to achieve this is explained in chapter 20.1.8. Using lazy property fetching of the manual. It requires a special build process.

Upvotes: 3

dunni
dunni

Reputation: 44545

You have to enable bytecode instrumentation to activate lazy loading for properties. If you don't have bytecode instrumentation enabled, Hibernate will ignore any properties about lazy loading (see the docs)

Upvotes: 1

Related Questions