Hey. I have read the HTML manual and bought Hibernate in Action and I am still none the wiser about exactly the best thing to do for a basic Class A has a List collection. By default we do not want to load the list. At some point we decide to load Class A and we now want the collection loaded. The following code below is the only solution that I have tried that works but it is described in Hibernate in Action as inefficient (immediate mode) without going into how to solve it in practice.
Thanks for any insight!
Hibernate version:
2.1.4
Mapping documents:
VERY long! Here is the part I am asking about:
Code:
<class name="com.qas.newmedia.intranet.pof.dto.POF"
table="tbl_POFs">
<id name="id" type="int" column="pof_id" unsaved-value="0">
<generator class="identity" />
</id>
<list name="lineItems" inverse="true" lazy="true" cascade="all">
<key column="pof_id"/>
<index column="line_item_id" />
<one-to-many class="com.qas.newmedia.intranet.pof.dto.LineItem" />
</class>
Code between sessionFactory.openSession() and session.close():Code:
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();
pof= (POF) session.load(POF.class, id);
List list = session.find(
"select elements(pof.lineItems) from POF as pof where pof.id = ?",
id,
Hibernate.INTEGER
);
pof.setLineItems(list);
tx.commit();
HibernateUtil.closeSession(session);
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
SQL Server 2000
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A