Note that there are some explanatory texts on larger screens.

plurals
  1. POWeired session error in lazy-fetch
    primarykey
    data
    text
    <p>The error is <code>failed to lazily initialize a collection, no session or session was closed</code>.</p> <p>There are many people asked nearly the same question, but the resolution are not so much intuitive. And, I think it's necessary to post another question to describe the strange error message:</p> <p>(I'm not going to paste the source codes here because it's too long.)</p> <blockquote> <pre><code>DEBUG [main] (AbstractPlatformTransactionManager.java:365) - Creating new transaction with name [com.bee32.plover.orm.feaCat.FeaturePlayer.tcList]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' DEBUG [main] (HibernateTransactionManager.java:493) - Opened new Session [org.hibernate.impl.SessionImpl@19006c9] for Hibernate transaction DEBUG [main] (HibernateTransactionManager.java:523) - Not preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@19006c9] DEBUG [main] (HibernateTemplate.java:397) - Found thread-bound Session for HibernateTemplate Hibernate: /* criteria query */ select ... ERROR [main] (LazyInitializationException.java:42) - failed to lazily initialize a collection, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380) ... at java.util.HashSet.&lt;init&gt;(HashSet.java:116) ... at org.hibernate.loader.Loader.list(Loader.java:2124) ... at org.springframework.orm.hibernate3.HibernateTemplate$5.doInHibernate(HibernateTemplate.java:590) ... DEBUG [main] (HibernateTemplate.java:422) - Not closing pre-bound Hibernate Session after HibernateTemplate DEBUG [main] (AbstractPlatformTransactionManager.java:843) - Initiating transaction rollback DEBUG [main] (HibernateTransactionManager.java:672) - Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@19006c9] DEBUG [main] (HibernateTransactionManager.java:734) - Closing Hibernate Session [org.hibernate.impl.SessionImpl@19006c9] after transaction </code></pre> </blockquote> <p>As you see, when lazy-fetch is trigged, the error occurred, there already have a thread-bound session, and it's not yet closed until the transaction is rolled back.</p> <p>So, why it reports there is <code>no session or session was closed</code>?</p> <p><strong>EDIT</strong> The related source:</p> <pre><code>@Transactional public void tcList() { for (Cat cat : dao.list()) { System.out.println("Saved cat: " + cat); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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