Shipment shipment = shipmentDao.getByDate(id, shipmentDate);
OrderDetail od = baseDao.getById(OrderDetail.class, id);
if (order == null) {
order = od.getOrder();
}
if (shipment == null) {
shipment = new Shipment();
shipment.setOrderDetail(od);
shipment.setTotal(total);
shipment.setQuantity(quantity);
shipment.setShipmentDate(shipmentDate);
shipment.setType(type);
baseDao.saveByObject(shipment);//这里执行保存成功
} else {
//因为Shipment是ManytoOne OrderDetail 并且是OrderDetail,这里获得的OrderDetail是lazy的od,这会造成下面的baseDao.updateByObject(od);不执行
//如何解决
shipment.setTotal(total);
shipment.setQuantity(quantity);
shipment.setType(type);
baseDao.updateByObject(shipment);//这里不执行更新,也不打印update sql
}
od.setShipment(total);
baseDao.updateByObject(od);
求大神帮忙
1.为何能保存到shipment,却不能update shipment,也不报错
2.如何解决获取的OrderDetail是lazy,我想从DB里获取,不是从缓存
另外一个方法
Shipment shipment = baseDao.getById(Shipment.class, id);
baseDao.deleteByObject(shipment);
OrderDetail od = shipment.getOrderDetail();
od.setShipment(od.getShipment() - shipment.getTotal());
baseDao.updateByObject(od);
Order order = od.getOrder();
order.setShipment(order.getShipment() - shipment.getTotal());
baseDao.updateByObject(order);
ProductionProcess process = productionProcessDao.getByOrderDetailAndDate(od.getId(), shipment.getShipmentDate());
process.setShipment(0);
这里第2行也出现不能删除shipment
Hibernate会优化执行的SQL,执行的SQL顺序Hibernate优化过后并不能保证一致。
baseDao.update之前先执行baseDao.get(); 会触发update事件
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。