hibernate4 could not initialize proxy - no Session

简介: hibernate4 could not initialize proxy - no Session

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


<!-- 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 的处理,配置后解决了错误

<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>


相关文章
|
Java 数据库连接 数据库
Hibernate 上下文中的 Proxy 是什么?
【8月更文挑战第21天】
325 0
|
缓存 安全 Java
|
缓存 安全 Java
Hibernate 中的 Session 是线程安全的吗?
【8月更文挑战第21天】
396 0
|
缓存 安全 Java
Hibernate 中的 Session 是什么?
【8月更文挑战第21天】
464 0
|
SQL 缓存 Java
Hibernate - Session管理与批量数据处理详解
Hibernate - Session管理与批量数据处理详解
399 0
|
存储 缓存 Java
Hibernate - Session方法与持久化对象详解
Hibernate - Session方法与持久化对象详解
480 0
|
SQL 缓存 Java
Hibernate - SessionFactory和Session详解
Hibernate - SessionFactory和Session详解
428 0
|
关系型数据库 MySQL Java
Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExcep linux下mysql修改连接超时wait_timeout修改后就ok了
Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExcep linux下mysql修改连接超时wait_timeout修改后就ok了
549 1
|
XML 存储 SQL
问:hibernate的sessionfactory是干嘛的?session又是干嘛的呢?
问:hibernate的sessionfactory是干嘛的?session又是干嘛的呢?
313 1
|
SQL Java 数据库连接
Hibernate中的Session对象
Hibernate中的Session对象