Executing an update/delete query

 执行新增修改的时候 默认是有事务的

entityManager.createNativeQuery(sql).executeUpdate();
加上事务注解即可


@Transactional
public void save(ApiLog apiLog){
String tableName=getTableName();

HttpServletRequest httpServletRequest = getHttpServletRequest();
apiLog.setHeader(getHeader(httpServletRequest))
.setQuery(httpServletRequest.getQueryString())
.setMethod(httpServletRequest.getMethod())
.setIp(getIpAddress(httpServletRequest))
.setUrl(httpServletRequest.getRequestURL().toString());
String sql=getSql(apiLog,tableName);
entityManager.createNativeQuery(sql).executeUpdate();
}