解决no--session的问题

Session

        上周在编写hibernate4的相关代码的时候,出现异常 org.hibernate.LazyInitializationException: could not initialize proxy - no Session  网上出现最多的解决方案是  openSessionInViewFilter

        形如:

1

2

3

4

5

6

7

8

9

10

11

12

13

<!-- open session filter -->

    <filter>

        <filter-name>openSessionInViewFilter</filter-name>

        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>

        <init-param> 

            <param-name>singleSession</param-name> 

            <param-value>true</param-value> 

        </init-param> 

        <init-param>

            <param-name>sessionFactoryBeanName</param-name>

            <param-value>sessionFactory</param-value>

        </init-param>

    </filter>


    同时,也参与配置了另外一个参数:

    在stackoverflow 上面找到一篇介绍 使用了 hibernate.enable_lazy_load_no_trans 的处理,配置后解决了错误:

    

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

<bean id="sessionFactory"

        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="dataSource" ref="dataSource" />

        <property name="packagesToScan">

            <list>

                <value>com.alexgaoyh</value>

            </list>

        </property>

        <property name="hibernateProperties">

            <props>

                <prop key="javax.persistence.validation.mode">none</prop>

                <prop key="hibernate.dialect">${hibernate.dialect}</prop>

                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>

                <prop key="hibernate.format_sql">true</prop>

                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>

                <prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>

                <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>

                <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>

                <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>

                <prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop>

                <prop key="hibernate.enable_lazy_load_no_trans">true</prop>

            </props>

        </property>

    </bean>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值