//dao方法:
public Spare updateSpare(Integer amount,Integer id){
String sql="Update Spare set spare_amout=spare_amout+"+ amount +" where device_id="+id+"";
return (Spare) super.findByHql(sql, null);
}
/////////////////////////////////////////////////////////////////////////////////////////
public List<T> findByHql(String hql, Object[] queryArgs) {
return getHibernateTemplate().find(hql, queryArgs);
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//业务
public void updateSpare(Spare spare, Integer amount, Integer id) {
spareDao.updateSpare(amount, id);
}
----------------------------------------------------
//action
Integer id=Integer.parseInt(sf.getDevice_id());
Integer amount=sf.getBuy_amount();
Spare spare= new Spare();
stockBo.create(stock);//进货表插入
isparebo.updateSpare(spare, amount, id); //库存表修改
---------------------------------------------------------------------
调试问题:
javax.servlet.ServletException: Not supported for DML operations; nested exception is org.hibernate.HibernateException: Not supported for DML operations
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.springframework.orm.hibernate3.HibernateSystemException: Not supported for DML operations; nested exception is org.hibernate.HibernateException: Not supported for DML operations
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:668)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:408)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:830)
zj.util.dao.genericdao.impl.GenericCommondHBImpl.findByHql(GenericCommondHBImpl.java:55)
zj.dao.hibernate.SpareDaoHBImpl.updateSpare(SpareDaoHBImpl.java:37)
zj.business.impl.SpareBoImpl.updateSpare(SpareBoImpl.java:49)
zj.struts.action.StockAction.insert(StockAction.java:68)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:589)
恳求各位帮帮
------解决方案--------------------
String sql = "Update Spare set spare_amout=:amout where device_id=:id"
int updateEntities = s.createQuery( sql)
.setString( "spare_amout", amout)
.setString( "device_id", id )
.executeUpdate();
试试这个,hibernate语法有时候要求比较严格,我也不大清楚,你试试吧