我正在开发一个基于 Spring、Hibernate 和 JSF 的 Web 应用程序,并且我面临一个已知问题,该问题之前已经讨论过几次。见下文 :
17:42:11,970 错误 [STDERR] 11 月 7 日。2012 17:42:11 javax.faces.component.UIInput updateModel GRAVE: createProjectForm:projectStatus: 处理您提交的信息时出错。17:42:11,972 信息 [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.
我尝试了以下解决方案但没有成功:(:
- OpenViewInSession 过滤器
- @Transactional 注解
- Hibernate.initialize(对象)
我认为我的问题与无法获得当前 Hibernate 会话的 JSF 有关,但我不知道如何解决这个问题。
我在用着 :
- JSF 1.2
- Richfaces 3.3.2
- 春天 2.5
- 休眠 3.2.5
- JBoss 4.2
在下面找到我的配置文件和源代码:
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>
应用程序上下文.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>
知道该怎么做吗?