感謝您使用h:selectMany標記的collectionType屬性來防止LazyInitializationException。
但是,而不是在一個不適當的論壇上發火焰,而不是在JSF 2.0中學習什麼新東西,併發布這個問題的一個完整的例子,以及如何解決它?
基點:
堆棧此錯誤的跟蹤:
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)
例如添加collectionType修復此錯誤(我使用的是自定義的驗證):
<h:selectManyListbox value="${technologyService.entity.associatedLabs}"
collectionType="java.util.ArrayList">
<f:validator validatorId="selectManyListboxValidator" />
<f:attribute name="maxItems" value="5" />
<f:selectItems value="${metadataService.activeLabSelectItems}" />
</h:selectManyListbox>