zoukankan      html  css  js  c++  java
  • hibernate懒加载异常处理

    1、实体类中使用lazy="false"

    2、lazy="ture"   在web.xml中加入

          程序代码
        <filter> 
         <filter-name>hibernateFilter</filter-name> 
         <filter-class> 
         org.springframework.orm.hibernate3.support.OpenSessionInViewFilter 
         </filter-class> 
       </filter 
       <filter-mapping> 
         <filter-name>hibernateFilter</filter-name> 
         <url-pattern>*.do</url-pattern> 
        </filter-mapping>
     
        此方式容易遇到Write operations are not allowed in read-only mode问题,解决方法:重写OpenSessionInViewFilter的2个方法
         public class OpenSessionInViewFilter extends org.springframework.orm.hibernate3.support.OpenSessionInViewFilter {
     

         
            /**
             * we do a different flushmode than in the codebase
             * here
             */
            protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
                    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
                    session.setFlushMode(FlushMode.COMMIT);
                    return session;
            }
            /**
             * we do an explicit flush here just in case
             * we do not have an automated flush
             */
            protected void closeSession(Session session, SessionFactory factory) {
                    session.flush();
                    super.closeSession(session, factory);
            }
    }

  • 相关阅读:
    python的相关基本操作
    asp.net core 验证码方案
    zookeeper常用命令
    谷粒学院_day10_技术点_nacos启动和服务注册演示
    springcloud-禁止eureka的保护模式
    springcloud-服务发现Discovery
    springcloud-actuator微服务信息完善
    springcloud-支付服务集群搭建
    rbac——界面、权限
    初识rbac
  • 原文地址:https://www.cnblogs.com/lengzhijun/p/4261670.html
Copyright © 2011-2022 走看看