The problem is conceptual, when I use
in my XHTML, hibernate do another select of 'objectAttribute' because the 'objectAttribute' is mapped by LAZY. I did not want this, I want the programmer build the HQL's in DAO's instead of let hibernate do this another select.
In order of that I would like to close the hibernate session in Facade layer.
My architecture is XHTML / Controller (ManagedBeans) / Facade / BO / DAO.
This problem is because I have been working in a project that has a big performance problem, we discovered that application do a lot of selects, the programmers did not build a good HQL.
For example, if a build a select like 'from Product' and the Product agregate 'productType' as a lazy object, when the XHTML invoke getProductType the hibernate proxy will do another select to retrieve ProductType, If the main select retrieve 200 records, the total select count will be 201 select because is 1 main select and 1 select from each record in order to retrieve producttype.
But if I build the select like 'from Product p left outer join p.productType' will be only one select with left join.
Could someone help me?
When the association is mapped Lazy, Hibernate will not read the other entity unless you do a join. If you want the entity also LOADED, you need to add the fetch keyword after the join. This will take care of loading. See the hibernate docs for a full explanation of this feature.
P.S. this is really a basic Hibernate question, so you should ask there.