@Override public void delete(Order t) { // only when order is not processed yet: if (!t.canCancel()) throw new OrderException("无法删除正在处理中的订单。"); // delete each OrderItem: for (OrderItem item : t.getOrderItems()) hibernateTemplate.delete(item); // delete Order object: hibernateTemplate.delete(t); }
public void create(Order order, List<OrderItem> items) { int payment = order.getPayment(); if (payment == Order.PAYMENT_FACE_TO_FACE) order.setState(Order.STATE_WATING_FOR_HANDLE); else order.setState(Order.STATE_WAITING_FOR_PAY); hibernateTemplate.save(order); for (OrderItem item : items) { item.setOrder(order); hibernateTemplate.save(item); } }
@Override public Order query(Serializable id) { Order order = super.query(id); hibernateTemplate.initialize(order.getOrderItems()); return order; }