Can only perform operation while a transaction is active.

<openjpa-2.2.1-r422266:1396819 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: Can only perform operation while a transaction is active.

在使用 openjpa的时候,抛出了如上的错误信息,后来检查之后,原因如下:

针对同一个事务管理器,在开启事务之后又再开启一次,即如下代码,在上一个方法调用:

markMsg(String[] ids,String userid) 时,本方法内部又重新开启了一次事务。
/***
	 * 标记已读消息
	 * @author JianWu Zhang
	 * <br>2015年3月30日 下午6:29:24
	 * @param request
	 * @param response
	 */
	public void markReadedMsg(HttpServletRequest request,
			HttpServletResponse response){
		AsyncContext act =ReqTool.ajax(request);
		MessageInfo info =new MessageInfo(MessageInfo.FAILE, "系统繁忙,请重试!");
		AjaxEntity ajaxEn =new AjaxEntity(AjaxType.JSON,info);
		try {
			String id =Def2Val.strNotNUll(request.getParameter("ids"));
			String []ids =id.split(",");
			SysFactory.getSysManager().beginTransaction(true);
			boolean result =markMsg(ids,UserTool.User(request, response,false).getId());
			SysFactory.getSysManager().commitTransaction();
			if(result==true){
				info.setDoResult(MessageInfo.SUCCESS);
				info.setMessage("标记成功!");
			}else{
				info.setDoResult(MessageInfo.FAILE);
				info.setMessage("标记失败!系统繁忙,请稍后重试");
			}
		} catch (Exception e) {
			log.error("个人中心模块---标记已阅读出错!",e);
		}finally{
			ajaxEn.setDate(info);
			new Thread(new AjaxRunnable(act,ajaxEn)).start();
		}

	}
/**
	 * 标记已阅读的消息
	 * @author JianWu Zhang
	 * <br>2015年3月31日 上午11:30:00
	 * @param ids
	 * @param userid
	 * @return
	 */
	public boolean markMsg(String[] ids,String userid){
		AccountMessageManager msgManager =SysFactory.getImplManager(AccountMessageManager.class);
		try {
			SysFactory.getSysManager().beginTransaction(true);
			boolean result= msgManager.markMsg(ids, DicUtil.READED, userid);
			SysFactory.getSysManager().commitTransaction();
			return result;
		} catch (Exception e) {
			log.error("标记已阅读的消息出错!", e);
			return false;
		}
	}
时间: 2024-10-08 04:09:08

Can only perform operation while a transaction is active.的相关文章

linux xfce4普通用户 mount usb提示: Not authorized to perform operation

问题:xfce4下,USB 硬盘能自动挂载并显示,但是普通用户操作时,提示:Not authorized to perform operation. 时间:20160928 os:gentoo + xfce4 + openrc 解决方法: cd /usr/share/polkit-1/actions nano *.udisks*.* 把相应权限都改成Yes即可. <action id="org.freedesktop.udisks2.filesystem-mount">  

Compensating Transaction Pattern(事务修正模式)

Undo the work performed by a series of steps, which together define an eventually consistent operation, if one or more of the steps fail. Operations that follow the eventual consistency model are commonly found in cloud-hosted applications that imple

Parallelized coherent read and writeback transaction processing system for use in a packet switched cache coherent multiprocessor system

A multiprocessor computer system is provided having a multiplicity of sub-systems and a main memory coupled to a system controller. An interconnect module, interconnects the main memory and sub-systems in accordance with interconnect control signals

Entity Framework 6.0 Tutorials(6):Transaction support

Transaction support: Entity Framework by default wraps Insert, Update or Delete operation in a transaction, whenever you execute SaveChanges(). EF starts a new transaction for each operation and completes the transaction when the operation finishes.

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

问题描述: 研发突然找我,遇到了mysql的 ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction,具体报错如下: org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158) Caused by: java.io .IOException: java.sql.SQLException: Lock wait timeout exceeded;

DFS lock handle &amp; inactive transaction branch

Event Waits Time(s) Avg wait (ms) % DB time Wait Class DFS lock handle 2,214 6,157 2781 66.08 Other DB CPU 2,107 22.62 inactive transaction branch 1,046 1,046 1000 11.23 Other cell smart table scan 4,910 8 2 0.09 User I/O SQL*Net more data to client

Windows 错误代码

Error Messages for Windows http://www.gregorybraun.com/MSWINERR.ZIP Server 4.0 Error Messages   Code Error Message 0 操作成功完成. 1 函数不正确. 2 系统找不到指定的文件. 3 系统找不到指定的路径. 4 系统无法打开文件. 5 拒绝访问. 6 句柄无效. 7 存储控制块被损坏. 8 存储空间不足,无法处理此命令. 9 存储控制块地址无效. 10 环境不正确. 11 试图加载

A multiprocessing system including an apparatus for optimizing spin-lock operations

A multiprocessing system having a plurality of processing nodes interconnected by an interconnect network. To optimize performance during spin-lock operations, a home agent prioritizes the servicing of read-to-own (RTO) transaction requests over the

Microsoft SQL Server Version List(SQL Server 版本)

原帖地址 What version of SQL Server do I have? This unofficial build chart lists all of the known Service Packs (SP), Cumulative Updates (CU), patches, hotfixes and other builds of MS SQL Server 2014, 2012, 2008 R2, 2008, 2005, 2000, 7.0, 6.5 and 6.0 tha