Hello all,
I am using Hibernate 3.0.
I have two classes: Technology_Type, Technology associated with each other in a one-to-many relation.
Mapping for Technology_Type is below:
Code:
.
.
.
<set name="technologies" inverse="true" order-by="name desc"
batch-size="2" where="name like upper('W%')" cascade="delete">
<key column="type_id" on-delete="cascade" ></key>
<one-to-many class="learn.hibernate.persistence.Technology"></one-to-many>
</set>
.
.
.
When I get the technologies beloning to a technology type everything is fine. But when I close the session (as shown in red), I get "...failed to lazily initialize a collection of role..."
// find the technologies under type say - 4
Technology_Type tt = (Technology_Type)ses.load(Technology_Type.class, new Long(4));
Set technologies = tt.getTechnologies();
Long tt_id = tt.getId();
String name = tt.getName();
ses.close(); System.out.println("There are "+technologies.size()+ " that belong to "+name +":");
When I have read all the properties of Technology_Type, I guess I should be able to close the session.
By placing the ses.close() after the System.out.println.... everything works fine.
Why?
J2EE_PRO
--------------------------
I think, therefore I survive
Code:
Code:
Code: