wiflish
Loving Life! Loving Coding!
posts - 98,comments - 98,trackbacks - 0
在web.xml文件中配置OpenSessionInViewFilter

    
<filter>
        
<filter-name>hibernateFilter</filter-name>
        
<filter-class>
            org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
        
</filter-class>
    </filter>
在spring的事务配置中:
<aop:config>
    
<aop:advisor id="managerTx" advice-ref="txAdvice"
        pointcut
="execution(* *..service.*Manager.*(..))" order="2" />
</aop:config>

<tx:advice id="txAdvice">
    
<tx:attributes>
        
<tx:method name="get*" read-only="true" />
        
<tx:method name="find*" read-only="true" />
        
<tx:method name="*" />
    
</tx:attributes>
</tx:advice>

这样的配置,当在容器中通过action调用service代码保存对象时,不能成功保存对象,
同时出现如下类似错误:
Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into
FlushMode.COMMIT
/AUTO or remove 'readOnly' marker from transaction definition.

这时修改filter的配置,增加如下代码:
    <filter>
        
<filter-name>hibernateFilter</filter-name>
        
<filter-class>
            org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
        
</filter-class>
        
<init-param>
            
<param-name>singleSession</param-name>
            
<param-value>false</param-value>
        
</init-param>
    
</filter>

这样就能成功保存对象了。

===================================================================
额。。。上面那个配置等于不用OpenSessionInViewFilter。。。 没意义。。

posted on 2007-04-11 20:33 想飞的鱼 阅读(4724) 评论(3)  编辑  收藏 所属分类: framework

FeedBack:
# re: 关于OpenSessionInViewFilter的配置
2007-04-13 17:04 | shydow
这等于没有使用open session in view  回复  更多评论
  
# re: 关于OpenSessionInViewFilter的配置
2008-08-21 16:00 | neo
这种贴也来发,根本没有搞清发生问题的原因是什么,你是绕过了问题,但是又遇上了一个新问题,就如楼上所说  回复  更多评论
  
# re: 关于OpenSessionInViewFilter的配置
2009-04-28 16:57 | 11
确实,问题是一个接一个的来,
Connection is read-only. Queries leading to data modification are not allowed  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: