关于使用OpenSessionInViewFilter遇到的两个问题

cf316985294 2012-05-30 02:31:48
filter配置如下:
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sf</param-value>
</init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>false</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
事物配置如下:
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sf"></property>
</bean>

<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sf" />
</bean>

<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.test..service.impl.*(..))" advice-ref="txAdvice"/>
</aop:config>

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="exists"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
一下有几种情况:
1.当不加入filter那段内容的时候,程序操作N次后卡住(此处我判断应该是事物没有起作用,打开的连接没有关闭,导致连接数超限),但我不知道为什么事物就不起作用了(当我加入filter那段,程序恢复正常)?
2.当filter段去掉
<init-param>
<param-name>singleSession</param-name>
<param-value>false</param-value>
</init-param>
程序插入或修改或删除时都报org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition ,想请教下 这段代码的作用是什么,加入这段代码事物有没有起作用?




...全文
89 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cf316985294 2012-05-31
  • 打赏
  • 举报
回复
悲剧,我的帖子沉下去了!
cf316985294 2012-05-31
  • 打赏
  • 举报
回复
悲剧,我的帖子沉下去了!

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧