我的問題很簡單,當我有 sku(@id of product) 時如何創建銷售物體?
父物體
public class Product {
@Id
private int sku;
private String name;
@OneToMany(mappedBy="product")
private Set<Sale> sales;
}
子物體
public class Sale {
@Id
@GeneratedValue
private int id;
@ManyToOne
@JoinColumn(name="sku", nullable=false)
private Product product;
...
}
uj5u.com熱心網友回復:
通過 id 查找產品,使用資料創建銷售,在新銷售中設定產品,保存銷售。假設彈簧資料和休眠,是這樣的:
Product product = productRepo.findById(id);
Sale sale = initWithData;
sale.setProduct(product);
saleRepo.save(sale);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/486345.html
