我有2个实体:Product和ProductLine。一个产品可以有许多ProductLines。我无法删除与特定ProductLine相关联的产品。
Product.java
@Entity
@Table(name = "PRODUCT")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
ProductLine.java
@Entity
@Table(name = "PRODUCTLINE")
@JsonSerialize
public class ProductLine {
@JsonIgnore
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
private String name;
@JsonIgnore
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "PRODUCTLINE_PRODUCT", joinColumns = @JoinColumn(name = "PRODUCTLINE_ID"), inverseJoinColumns = @JoinColumn(name = "PRODUCT_ID"))
private List<Product> products;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
您可以在 - https://github.com/iftekharkhan09/ProductRepository.git
中找到整个代码代码处于Spring引导状态。
请在邮递员中执行以下内容:
http://localhost:8080/data/addProductLine?productLine=apple
http://localhost:8080/data/addProduct
体:
[
{
"productLine": "apple",
"productName":"mac"
}
,
{
"productLine": "apple",
"productName":"iphone"
}
]
删除产品(POST): - http://localhost:8080/data/deleteProduct?productLineName=apple&productName=mac
在控制台中,我看不到要触发的删除查询。
任何帮助都将受到高度赞赏。