mykola
mykola

Reputation: 1808

How to catch hibernate's lazy loadings?

I want to optimize a page where a lot of objects are loaded many of which use hibernate's lazy loading for their properties. But it's hard to find all of them manually because when I see say someItem.getSmth() I don't know that it's actually lazy loaded (it's not my code) besides I can skip some of these loadings anyway hence I need some automatic way of finding it. I tried to turn on hibernate's SQL logging but it's impossible to read it because it writes about 50 megs of logs per page load and it doesn't tell me where the query was called from. Is it possible to know somehow which objects are lazy loaded and from where?

Upvotes: 2

Views: 99

Answers (1)

A4L
A4L

Reputation: 17595

Is it possible to know somehow which objects are lazy loaded and from where?

You could parse your entity beans for the annotations OneToOne, OneToMany, ManyToOne and ManyToMany, if found, check for the property fetch whether it has the value FetchType.LAZY.

This could allow you to know which objects a lazy loaded and from which classes but not methods where the call is.

Upvotes: 1

Related Questions