我有具有@PreUpdate EntityListener
的Orderitem实体但是当我首先调用更新Order方法时,它获取OrderItems然后更新顺序,但问题是orderItem也在通过@PreUpdate EntityListener更新订单后更新。
@Entity
@Data
@Table(name = "order_item")
@EntityListeners({AuditEntityListener.class})
public class OrderItem implements Serializable {
.
.
.
@CreatedByName
private String createdByName;
@UpdatedByName
private String updatedByName;
}
@Entity
@Table(name = "\"order\"")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Order implements Serializable {
private long id;
.
.
.
private List<OrderItem> orderItems;
}
@Service
public class AuditEntityListener {
@PreUpdate
public void onPreUpdate(Object o) {
AuditorAwareImpl impl = new AuditorAwareImpl();
User user = impl.getCurrentAuditor();
if (user != null) {
auditModel.setUpdatedBy(String.valueOf(user.getId()));
auditModel.setUpdatedByName(user.getFullName());
}
}
}
@Service
public class OrderServiceImpl implements OrderService {
public Order updateOrder(long orderId) {
Order order = orderRepository.findOne(orderId);
if (order != null) {
List<OrderItem> orderItems = orderItemService.findByOrderId(orderId);
order.setOrderItems(orderItems);
.
}
// set other fields
orderRepository.save(order);
return order;
}
}
当我调用updateOrder方法然后执行后,它还通过AuditEntityListener更新orderItem字段updatedBy和updatedByName,我不希望在调用订单更新时。请帮忙