web.xml配置如下<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
<init-param> 
            <param-name>singleSession</param-name> 
            <param-value>true</param-value>            
        </init-param> 

<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
使用后延迟加载得到解决了,但是原先能进行的写操作都不能进行了,求高手解决

解决方案 »

  1.   

    用了OpenSessionInViewFilter就不能在程序中手动关闭session手动关闭会出错
      

  2.   

    可能我没说清楚 我没想关闭session 我只是想用hibernateTemplate获取session进行insert操作。。
      

  3.   

    木有人吗我感觉是session变成了readonly,但是我并没有设置啊。
    自己顶啊
      

  4.   

    使用OpenSessionInViewFilter要设事务控制
      

  5.   

    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
    <props>
                    <prop key="add*">PROPAGATION_REQUIRED</prop>
                    <prop key="del*">PROPAGATION_REQUIRED</prop>
                    <prop key="update*">PROPAGATION_REQUIRED</prop>
                    <prop key="query*">readOnly</prop>
                    <prop key="get*">readOnly</prop>
                    <prop key="find*">readOnly</prop>
                    <prop key="check*">PROPAGATION_REQUIRED</prop>
                    <prop key="operate*">PROPAGATION_REQUIRED</prop>
                    <prop key="batch*">PROPAGATION_REQUIRED</prop>
                    <prop key="deploy*">PROPAGATION_REQUIRED</prop>
                    <prop key="exec*">PROPAGATION_REQUIRED</prop>
                    <prop key="init*">PROPAGATION_REQUIRED</prop>
                     <prop key="permission*">PROPAGATION_REQUIRED</prop>
                </props>
    </property>
    </bean>