Hi,
When use lazy=false, the collection is aways loaded by Hibernate,
causing generation of sql.
I did the use of proxy and lazy=true. In the mapped class I put
proxy tag to load this only if the user want:
Code:
<hibernate-mapping>
<class name="manager.Company" table="empresa"
proxy="manager.Company"
.
.
.
.
<bag name="companyAccounts" inverse="true" lazy="true">
<key column="id_company"/>
<one-to-many class=".manager.CompanyAccount"/>
</bag>
.
.
.
but, if you want the company accounts, u need to use fetch on the HQL:
Code:
from Company c";
left join fetch c.companyAccounts ca";
and Hibernate.initialize when You use the session.load or session.get:
Code:
company = (Company) session.load(Company.class, idCompany,
session, LockMode.UPGRADE);
Hibernate.initialize(company);
// loading the list of company accounts
Hibernate.initialize(company.getCompanyAccounts());