<!-- Clasa Proiect-->
<class catalog="tema3" name="com.tema3.tables.Proiect" table="proiect" lazy="false">
<id column="proiect_id" name="id">
<generator class="native"/>
</id>
<property name="nume" type="text" />
<set name="itemList" table="proiect_item" fetch="select">
<key column="proiect_id"/>
<many-to-many column="item_id" unique="true" class="com.tema3.tables.Item"/>
</set>
</class> </class>
that is my mapping class.
the code in wich i call an instantiation is :
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query q = session.createQuery("from Proiect");
List<Proiect> lists = HibernateUtil.listAndCast(q);
session.getTransaction().commit();
obj = lists;
and this is listandCastMethod:
public static <T> List<T> listAndCast(Query q) {
@SuppressWarnings("unchecked")
List list = q.list();
return list;
}
And i keep geting a :
May 2, 2011 4:38:03 PM org.hibernate.LazyInitializationException <init>
SEVERE: failed to lazily initialize a collection of role: com.tema3.tables.Proiect.itemList, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.tema3.tables.Proiect.itemList, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
but the thing is that the fields of Proiect class are populated except the Items set where i get this exception, but i want the items set to be populated.How can i do that?