标签:
场景:hibernate3更换hibernate4后,查询对象时抛如下异常
找不到关联的类
解决方法:
1.方法一
打开hbm.xml文件
<many-one>
改为
lazy="false"
2. 方法二
在web.xml文件添加
< filter > < filter-name > HibernateOpenSession</ filter-name > < filter-class > org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</ filter-class > </ filter > < filter-mapping > < filter-name > HibernateOpenSession</ filter-name > < url-pattern > /*</ url-pattern > </ filter-mapping >
注:OpenSessionInViewFilter类中有个属性叫 sessionFactoryBeanName默认值为sessionFactory,如果Spring中配置的SessionFactory不叫这个名字时,需要指定SessionFactory的名字,否则会引起org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘sessionFactory‘ is defined异常。
< filter > < filter-name > HibernateOpenSession</ filter-name > < filter-class > org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</ filter-class > < init-param > < param-name > sessionFactoryBeanName</ param-name > < param-value > mySessionFactory</ param-value > </ init-param > </ filter > < filter-mapping > < filter-name > HibernateOpenSession</ filter-name > < url-pattern > /*</ url-pattern > </ filter-mapping >
标签:
原文地址:http://www.cnblogs.com/tongxinyuan/p/4432979.html