为了解决Hibernate延迟加载问题,我在web.xml中加入了OpenSessionInViewFilter配置
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter><filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
我的事务配置代码:
<!----><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"><!----> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath*:spring/*.properties</value> </list> </property> </bean> <!----> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.zx.blog.*.service.impl.*Service*.*(..))" advice-ref="txAdvice"> </aop:config> <!----> <tx:advice id="txAdvice"> <tx:attributes> <tx:method name="save*"> <tx:method name="update*"> <tx:method name="remove*"> <tx:method name="delete*"> <tx:method name="get*" read-only="true"> <tx:method name="load*" read-only="true"> <tx:method name="find*" read-only="true"> </tx:attributes> </tx:advice>
</beans>
但问题出来了,在添加数据保存的时候老是提示 org.springframework.dao.InvalidDataAccessApiUsageException: 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.
数据保存不了。不知那位高手是否也遇到过此问题,有什么好的解决办法呢?