我正在开发基于Spring,Hibernate和JSF的Web应用程序,并且我面临着一个已经多次讨论过的已知问题。见下文:
17:42:11,970 ERROR [STDERR] 7 nov。 2012 17:42:11 javax.faces.component.UIInput updateModel GRAVE:createProjectForm:projectStatus:处理提交的信息时发生错误。 17:42:11,972 INFO [STDOUT] 17:42:11错误org.hibernate.LazyInitializationException无法初始化代理 - 没有会话 org.hibernate.LazyInitializationException:无法初始化代理 - 没有会话 在org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) 在org.hibernate.proxy.pojo.BasicLazyInitializer.invoke(BasicLazyInitializer.java:75) 在org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:160) 在com.company.entity.TLsta _ $$ _ javassist_6.setLStat(TLsta _ $$ _ javassist_6.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) 在javax.el.BeanELResolver.setValue(BeanELResolver.java:108) 在javax.el.CompositeELResolver.setValue(CompositeELResolver.java:68) at com.sun.faces.el.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:100) 在org.apache.el.parser.AstValue.setValue(AstValue.java:114) at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249) at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:93) 在javax.faces.component.UIInput.updateModel(UIInput.java:771) 在javax.faces.component.UIInput.processUpdates(UIInput.java:703) 在javax.faces.component.UIForm.processUpdates(UIForm.java:261) 在org.ajax4jsf.component.AjaxViewRoot $ 2.invokeContextCallback(AjaxViewRoot.java:419) 在org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:235) 在org.ajax4jsf.component.AjaxViewRoot.processUpdates(AjaxViewRoot.java:435) at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78) 在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) 在com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 在javax.faces.webapp.FacesServlet.service(FacesServlet.java:265) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178) 在org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) 在org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388) 在org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在org.springframework.security.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:394) 在org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) 在org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) 在org.springframework.security.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:406) 在org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67) 在org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) 在org.springframework.security.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:406) at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101) 在org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) 在org.springframework.security.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:406) 在org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:10 在org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) 在org.springframework.security.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:406) 在org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareReque) 在org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) 在org.springframework.security.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:406) 在org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:278) 在org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) 在org.springframework.security.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:406) 在org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89) 在org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) 在org.springframework.security.util.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:406) at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter) 在org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
我尝试了以下解决方案但没有成功:(:
我认为我的问题与JSF无关,后者无法获得当前的Hibernate sesssion,但我不知道如何解决这个问题。
我正在使用:
在下面找到我的配置文件和源代码:
的web.xml
<!-- Hibernate filter -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<!-- Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<!-- jsf listener -->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- spring listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener- class>
</listener>
<listener>
<listener- class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- jsf servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- RichFaces login -->
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
的applicationContext.xml
<!-- DataSource -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:oracleDS</value>
</property>
</bean>
<!-- Session Factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="mappingLocations" value="classpath:*.hbm.xml" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<!-- Generic DAO -->
<bean id="genericDAO" class="com.company.dao.GenericDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="genericManager" class="com.company.services.GenericManagerImpl">
<property name="dao" ref="genericDAO"/>
</bean>
<context:component-scan base-package="com.company">
<context:include-filter type="regex" expression="com.company.beans.projectdirectory.Maintain*"/>
<context:include-filter type="regex" expression="com.company.beans.projectdirectory.services.ProjectDirectoryManager"/>
<context:include-filter type="regex" expression="com.company.beans.app.*"/>
</context:component-scan>
<context:annotation-config />
Create.xhtml,其中存在导致错误的属性访问:
<rich:comboBox value="#{createProjectBean.project.TPsta.PStat}"id="projectStatus" selectFirstOnUpdate="false" width="145"
required="true" requiredMessage="#{msg.CMP_requiredPrjStatusError}">
<f:selectItems value="#{createProjectBean.projectStatusOptions}" />
</rich:comboBox>
知道该怎么做?
答案 0 :(得分:0)
看起来你在'updateModelValuesPhase'中遇到了这个异常,它发生在'invoke application'阶段之前。 “调用应用程序”阶段是您通常执行大部分处理的地方。
如果您正在使用openSessionInView过滤器并仍然收到此异常,则可能是您在上一次请求期间加载了代理,但在当前请求期间尝试访问它。由于代理与已关闭的旧会话相关联,因此会出现LazyInitialization异常。