Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks for the hint to use the collectionType attribute for h:selectMany tags to prevent the LazyInitializationException.</p> <p><em>However</em>, instead of flaming about it in an inappropriate forum, how about learning what's new in JSF 2.0, and posting a full example of this problem and how to fix it? </p> <p>Groundwork:</p> <ul> <li>Mojarra 2.1 is the JSF 2 Reference Implementation (see <a href="https://stackoverflow.com/questions/7162190/what-is-mojarra">What is Mojarra</a>)</li> <li><a href="http://docs.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/h/selectManyCheckbox.html" rel="nofollow noreferrer">h:selectManyCheckbox VLD</a> documentation describes how to use the collectionType attribute (new in JSF 2.0)</li> <li>this problem affects validation of h:selectManyCheckbox, h:selectManyListBox, and h:selectManyMenu tags</li> </ul> <p>Stack Trace of this error:</p> <blockquote> <p>Feb 04, 2013 1:20:50 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute WARNING: 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:383) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375) at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122) at org.hibernate.collection.PersistentBag.isEmpty(PersistentBag.java:255) at javax.faces.component.UIInput.isEmpty(UIInput.java:1257) at javax.faces.component.UIInput.validateValue(UIInput.java:1144) at javax.faces.component.UISelectMany.validateValue(UISelectMany.java:579)</p> </blockquote> <p>Example adding collectionType to fix this error (I am using a custom validator):</p> <pre><code>&lt;h:selectManyListbox value="${technologyService.entity.associatedLabs}" collectionType="java.util.ArrayList"&gt; &lt;f:validator validatorId="selectManyListboxValidator" /&gt; &lt;f:attribute name="maxItems" value="5" /&gt; &lt;f:selectItems value="${metadataService.activeLabSelectItems}" /&gt; &lt;/h:selectManyListbox&gt; </code></pre>
 

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