码迷,mamicode.com
首页 > Web开发 > 详细

hibernate4--

时间:2015-04-16 19:19:24      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

场景: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 >

 

hibernate4--

标签:

原文地址:http://www.cnblogs.com/tongxinyuan/p/4432979.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!