【发布时间】:2011-08-27 09:40:12
【问题描述】:
我正在尝试使用下面的代码运行 mysql sql 语句;
public void createUpdate(Tsaleline entity) {
//Insert
String sql = "Insert into tSaleLine (CenterId, ProductId, Price, VATRate) "
+ "Select :centerId, :productId, :price, :vatrate "
+ "where (Select count(*) from tSaleLine where CenterId = :centerId and ProductId = :productId)=0; "
//Update
+ "Update tSaleLine "
+ "set CenterId = :centerId, "
+ "ProductId = :productId, "
+ "Price = :price, "
+ "VATRate = :vatrate "
+ "where CenterId = :centerId and ProductId = :productId; ";
Query q = getEntityManager().createNativeQuery(sql);
q.setParameter("centerId", entity.getCenterId())
.setParameter("productId", entity.getProductId())
.setParameter("price", entity.getPrice())
.setParameter("vatrate", entity.getVATRate())
.executeUpdate();
}
}
但它会出现错误:
异常
org.apache.jasper.JasperException: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: 无法执行本机批量操作查询
【问题讨论】: