General cenario:
Lazy + Open Session in View filter pattern + Request scope + JSF
I have a cenario where there are many large and composed objects (many-to-one, one-to-many, many-to-many and so on). So i need hibernate lazy fetching to avoid memory overcharge on collections retrieval. In all the cases, those collections are retrieved by some DAO, on methods like:
Code:
public Collection <LCR> getAll() throws ExceptionDAO {
Session session = DAOHibernateFactory.getSession();
try {
List<LCR> lcrs = session .createCriteria(LCR.class).list();
return lcrs;
} catch (Exception e) {
//on except, rollback and recreate session
DAOHibernateFactory.recreateHibernateSession();
throw new ExceptionDAO (e.getMessage());
}
}
To present all LCR´s, im using JSF DataTable, but mysteriously, some fields are not showed when should be. Those fields, are exactly the fields that should be automatically retrieved by Hibernate on demand (what i understand that should be lazy fetching). When i change the hibernate mappings and put
Code:
lazy="false"
and
Code:
session.flush()
before
Code:
return lcrs;
, them it works (the correct sqls are executed and the fields are retrieved from underlying classes) .
What is wrong? Im thinking wrong about Lazy fetching?
Hibernate version: 3.2.1.ga
Mapping documents:Relevant fields:
Hibernate.cfg
Code:
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="current_session_context_class">thread</property>
Name and version of the database you are using:
HSQLDB