我在spring context.xml中有以下内容。获取错误执行更新/删除。即使有q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
或没有这个。可能是我缺少一些更新表的配置
@Override
@Transactional(propagation = Propagation.REQUIRED)
public Boolean updateXXXX(final EO workflowHistory) {
Boolean updateFlag=false;
String que = "update table \n" +
"set status =:statusname , \n" +
"actor =:actor \n" +
"where ID = ( \n" +
"select MAX(id) from table \n" +
"where \n" +
"id =:processInstanceID)";
try{
final Query q = entityManager.createNativeQuery(que);
System.out.println("11 query...."+q.getLockMode());
q.setParameter("actor", workflowHistory.getActor());
q.setParameter("statusname", workflowHistory.getStatus());
q.setParameter("processInstanceID", workflowHistory.getProcessinstanceid());
q.executeUpdate();
} catch(Exception e){
System.out.println("In updateWorkflowHistory....");
e.printStackTrace();
}
updateFlag=true;
return updateFlag;
}
答案 0 :(得分:0)
将以下配置添加到弹簧上下文xml中
tx:annotation-driven transaction-manager =“transactionManager”
将解决问题