当前位置: 代码迷 >> J2EE >> 调用hibernate的save步骤,控制台打印出的语句却是update而不是insert
  详细解决方案

调用hibernate的save步骤,控制台打印出的语句却是update而不是insert

热度:69   发布时间:2016-04-22 00:37:05.0
调用hibernate的save方法,控制台打印出的语句却是update而不是insert
代码:
public ActionForward saveForecastType(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String url = "forecastType/forecastType/indexforecastType.ftl";
String path = "message/sucess.ftl";
SysUser user = (SysUser) request.getSession().getAttribute("user");
String infoId = (String) getService().getForecastTypeManager()
.getGeneratId();// 用于生成新的Id
ForecastType info = new ForecastType();
Map root = new HashMap();
root.put("url", url);
String vegetableTypeId = (String) request.getParameter("vegetableTypeId");
String oldPri = (String) request.getParameter("oldPrice");
double oldPrice = Double.parseDouble(oldPri);
String pri = (String) request.getParameter("price");
double price = Double.parseDouble(pri);
String oldSa = (String) request.getParameter("oldSale");
double oldSale = Double.parseDouble(oldSa);
String sal = (String) request.getParameter("sale");
double sale = Double.parseDouble(sal);
System.out.println("vegetableTypeId:"+vegetableTypeId+" oldPrice:"+oldPrice+" price:"+price+" oldSale:"+oldSale+"sale:"+sale);

//开始计算系数
double e = 0;
double q = sale-oldSale;
System.out.println("q:"+q);
double p = price-oldPrice;
System.out.println("p:"+p);
e = (q/p)*(oldPrice/oldSale);
System.out.println("e: "+e);

info.setE(e);
info.setOldPrice(oldPrice);
info.setPrice(price);
info.setOldSale(oldSale);
info.setSale(sale);
if (vegetableTypeId != null) {
VegetableType ct = new VegetableType();
ct.setId(vegetableTypeId);
info.setVegetableType(ct);
}
info.setCreator(user);
info.setCreateTime(new Date());

if (getService().getForecastTypeManager().save(info)) {
root.put("message", "操作成功");
} else {
path = "message/failed.ftl";
root.put("message", "操作失败");
}
super.goToFtl(path, root, request, response);
return null;
}

------解决方案--------------------
if (getService().getForecastTypeManager().save(info)) {这行弄个断点,看下info和getService().getForecastTypeManager().save(info)的值各是什么,还有,怎么没有对象调用getService().getForecastTypeManager().save(info)它。。。
  相关解决方案