Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use eager Instantiation in Hibernate?
    text
    copied!<pre><code>&lt;!-- Clasa Proiect--&gt; &lt;class catalog="tema3" name="com.tema3.tables.Proiect" table="proiect" lazy="false"&gt; &lt;id column="proiect_id" name="id"&gt; &lt;generator class="native"/&gt; &lt;/id&gt; &lt;property name="nume" type="text" /&gt; &lt;set name="itemList" table="proiect_item" fetch="select"&gt; &lt;key column="proiect_id"/&gt; &lt;many-to-many column="item_id" unique="true" class="com.tema3.tables.Item"/&gt; &lt;/set&gt; &lt;/class&gt; &lt;/class&gt; </code></pre> <p>that is my mapping class.<br> the code in wich i call an instantiation is :</p> <pre><code>Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Query q = session.createQuery("from Proiect"); List&lt;Proiect&gt; lists = HibernateUtil.listAndCast(q); session.getTransaction().commit(); obj = lists; </code></pre> <p>and this is listandCastMethod: </p> <pre><code>public static &lt;T&gt; List&lt;T&gt; listAndCast(Query q) { @SuppressWarnings("unchecked") List list = q.list(); return list; } </code></pre> <p>And i keep geting a : </p> <pre><code>May 2, 2011 4:38:03 PM org.hibernate.LazyInitializationException &lt;init&gt; 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) </code></pre> <p>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? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload