在web.xml文件中配置OpenSessionInViewFilter
< filter >
< filter-name > hibernateFilter </ filter-name >
< filter-class >
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</ filter-class >
</ filter >在spring的事务配置中:
这样的配置,当在容器中通过action调用service代码保存对象时,不能成功保存对象,
同时出现如下类似错误:
这时修改filter的配置,增加如下代码:
这样就能成功保存对象了。
===================================================================
额。。。上面那个配置等于不用OpenSessionInViewFilter。。。 没意义。。
< filter >
< filter-name > hibernateFilter </ filter-name >
< filter-class >
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</ filter-class >
</ filter >
<
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 >
< 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.
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 >
< 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。。。 没意义。。