I am trying to figure out why there are so many SQLs when I use HibernateTemplate's find* methods. So, for example:
Basically, this should find applicant and a few non-lazy/one-to-one collections. So, I should see in my logs approximately 3 SQLs. Applicant however has another 10 associated collections, each of which are declared lazy in hibernate config files. When I run the query above I see about 13 queries, which means that all of my lazy collections are being initialized.Code:List l = getHibernateTemplate ().findByNamedQueryAndNamedParam ( "findApplicantByUsername", new String [] { "userName" }, new Object [] { username });
When I run the following code (no spring):
It works correctly, no lazy collections are initialized, only 3SQLs are issued.Code:Session s = sessions.openSession (); Query q = s.getNamedQuery ("findApplicantByUsername"); q.setParameter ("userName", "u7uhicuj"); List results = q.list (); results.get (0);
What did I mess up? What can I do to revert to the desired lazy behavior?
Any help is really appreciated!
PS> I did see couple of posts about the same problem but have not seen any response.


Reply With Quote