异常:Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
web.xml内容:
<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>*.do</url-pattern>
</filter-mapping>
spring事件配置如下:
<aop:config>
<aop:pointcut id="txServices" expression="execution(* com.cnlive.dms.service..*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txServices"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
Service中是这样的:
@Override
public boolean createAdmin(Admin admin) {
// TODO Auto-generated method stub
Admin ad=adminDao.getAdminByUsername(admin.getUsername());
if(ad==null){
adminDao.insertAdmin(admin);
return true;
}
return false;
}
在运行到createAdmin方法中的adminDao.insertAdmin(admin);时就报异常。
解决方法:
将createAdmin方法配置到spring的事件中管理,添加了以下的一条配置
<tx:method name="create*" propagation="REQUIRED"/>
具体spring事件配置如下:
<aop:config>
<aop:pointcut id="txServices" expression="execution(* com.cnlive.dms.service..*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txServices"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
呵呵!问题就这样简单的解决了!不知道我们碰到的问题是否一样!
分享到:
相关推荐
使用Spring提供的Open Session In View而引起Write operations are not allowed in read-only mode (FlushMode.NEVER) 错误解决
Prerequisites: Java VM 1.8 Open a command shell/window, browse to where you ...Using the --help option will show the allowed command line arguments. 更多查看: https://github.com/WebGoat/WebGoat
在线封装和离线封装驱动 ... Description ...Adds the blacklisted ESXi 5.1 built-in ...Requires MaintMode Live Install Allowed Live Remove Allowed Stateless Ready Overlay Yes No No Yes No
2015-01-16: Version 8.039.01: Changed driver code to not use IP checksum hardware offload (caused various issues with networking in VMs) 2015-01-05: Version 8.039.00: Original version
解决web.xml中 <page-encoding>UTF-8</page-encoding>报错。错误提示: cvc-complex-type.2.4.a: Invalid content was found starting with element 'page-encoding'. One of '{"http:// java.sun....
Requires MaintMode Live Install Allowed Live Remove Allowed Stateless Ready Overlay Yes No No Yes No Additional links Related VMware Forum's post Package updated to include missing device IDs 1502...
NOTE: Windows executables in SDK are not signed so you may encounter security warnings on W8 and W10. On MacOS you may need to run SDK executables directly from console as they are not signed too.
When True then in ftmPanning mode will be shown only cached image of the initial client area. All parts outside will paints of the TFlexPanel.Brush. When returning from ftmPanning mode the complete ...
NOTE: sciter.dlls, sciter.exe and notes.exe Windows executables in SDK are digitally signed now. On MacOS you may need to run SDK executables directly from console as they are not signed too.
Requires MaintMode Live Install Allowed Live Remove Allowed Stateless Ready Overlay Yes No No Yes No Additional links VMware Communities thread about running VMware ESXi inside Hyper-V Build ...
开源项目-pawelad-just-scored.zip,为世界杯球迷提供lambda动力的Slack应用程序
directories that will not be allowed to be processed by Diskeeper. Event Logging ------------- Diskeeper records information about its activity in two ways. First, general information about ...
This document contains technical specifications for biometric data mandated or allowed in [FIPS]. These specifications reflect the design goals of interoperability, performance and security of the PIV...
You are likely to have seen much of the material in the appendix chapters before having read this book (although the specific notational conventions we use may differ in some cases from what you have...
TreeAge Pro 2013 User's Manual TreeAge Software embarked on an ambitious project to rewrite the software within the Eclipse development environment. Eclipse is a customizable development environment ...
Use the post template feature -located in campaign settings-. For example: {content} <p><a >Link to the original site</a></p> = Why isn’t the full article showing? = Because the feed you're using ...
从3GPP协议和UE端行为分析5G gmm cause #27的网络问题
开源项目-averagesecurityguy-spf.zip,Parse SPF records. Check for allowed clients.
- Accessing without a password If you do not know the password, the SCS project can be opened in read-only mode without entering the password after checking [Read Only]. In this status, the users are...
The self paced courses below are provided to help you increase your knowledge of UEFI and EDK II and to aid you in performing UEFI- and EDK II-related tasks. These courses are provided and produced as...