Я начал использовать IceFaces и столкнулся с проблемой при попытке поддержки drag'n'drop.
IceFaces 2.0.0
JSF 2.0
Mojarra 2.0.2 (FCS b10) (JSF reference implementation)
Spring 3.0.3
Hibernate 3.5.1-Final
JPA 2.0 (with OpenEntityManagerInViewFilter)
Проблема - LazyInitializationException
при удалении.Моим первым выводом было неверное управление настройками жизненного цикла контекста постоянства, но после нескольких часов игры с настройками, зависимостями и отладкой я обнаружил странную вещь: реализация JSF
создает экземпляр PersistentSet
путем отражения с конструктором по умолчанию (!) В RESTORE_VIEW phase
и пытается добавить значения к нему.Это действие вызывает LazyInitializationException
, поскольку PersistentSet
создается как простая коллекция, такая как ArrayList
, и не настроена должным образом (сеанс не установлен).
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 org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected
(AbstractPersistentCollection.java:372)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
at org.hibernate.collection.PersistentSet.add(PersistentSet.java:212)
at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1582)
at javax.faces.component.ComponentStateHelper.restoreState(ComponentStateHelper.java:290)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1444)
at com.icesoft.faces.component.panelseries.UISeries.restoreState(UISeries.java:642)
at com.icesoft.faces.component.panelseries.PanelSeries.restoreState(PanelSeries.java:138)
at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:231)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:147)
at com.icesoft.faces.component.panelseries.UISeries.visitTree(UISeries.java:814)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
at javax.faces.component.UIForm.visitTree(UIForm.java:333)
at com.icesoft.faces.component.panelseries.UISeries.visitColumnsAndRows(UISeries.java:898)
at com.icesoft.faces.component.panelseries.UISeries.visitTree(UISeries.java:832)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:223)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:177)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:131)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:430)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:143)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:199)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
javax.faces.FacesException: Unexpected error restoring state for component with id castle-list:j_idt12:castle-resident-list.
Cause: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed.
at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:239)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:147)
at com.icesoft.faces.component.panelseries.UISeries.visitTree(UISeries.java:814)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
at javax.faces.component.UIForm.visitTree(UIForm.java:333)
at com.icesoft.faces.component.panelseries.UISeries.visitColumnsAndRows(UISeries.java:898)
at com.icesoft.faces.component.panelseries.UISeries.visitTree(UISeries.java:832)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:223)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:177)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:131)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:430)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:143)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:199)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: 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 org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected
(AbstractPersistentCollection.java:372)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
at org.hibernate.collection.PersistentSet.add(PersistentSet.java:212)
at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1582)
at javax.faces.component.ComponentStateHelper.restoreState(ComponentStateHelper.java:290)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1444)
at com.icesoft.faces.component.panelseries.UISeries.restoreState(UISeries.java:642)
at com.icesoft.faces.component.panelseries.PanelSeries.restoreState(PanelSeries.java:138)
at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:231)
... 34 more
Этот код библиотеки реализации JSF содержит проблему:
(javax / Faces / component / UIComponentBase.java: 1566-1591):
if (stateObj instanceof List) {
List<StateHolderSaver> stateList = (List<StateHolderSaver>) stateObj;
Collection<Object> retCollection = null;
StateHolderSaver collectionSaver = stateList.get(0);
Class collectionClass = (Class) collectionSaver.restore(context);
try {
retCollection = (Collection<Object>) collectionClass.newInstance(); //(*)
}
catch (Exception e) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
throw new IllegalStateException("Unknown object type");
}
for (int i = 1, len = stateList.size(); i < len; i++) {
try {
retCollection.add(stateList.get(i).restore(context)); //(**)
} catch (ClassCastException cce) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE, cce.toString(), cce);
}
throw new IllegalStateException("Unknown object type");
}
}
result = retCollection;
}
*
в моем случае «collectionClass» - это «org.hibernate.collection.PersistentSet ". **
" retCollection.add "результаты вызова LazyInitializationException
Простой проект maven можно загрузить здесь .просто запустите его как веб-приложение, создайте несколько записей в разделах «Герои» и «Замки», а затем попробуйте связать их с помощью перетаскивания в разделе «Замки и герои».
Не яснокто отвечает за эту проблему - JSF RI, IceFaces или мои руки =) Я уже публиковал эту проблему на форумах IceFaces и Oracle:
http://www.icefaces.org/JForum/posts/list/18539.page
http://forums.oracle.com/forums/thread.jspa?messageID=9328036
Посоветуйте мне какие-нибудь обходные пути или укажите на мои ошибки, пожалуйста =)