Answer the question
In order to leave comments, you need to log in
JPA. How to implement the @ManyToMany relationship?
Formally, there is a connection between the two tables, but the table created automatically includes a composite primary key, which consists of two fields that I connected ... It is impossible to remove the primary key modifier. What am I doing wrong?
IDE Idea (if something depends on it).
OrdersDB.class
...
private List<ProductsDB> products = new ArrayList<>();
@ManyToMany
@JoinTable(name = "ORDER_PRODUCTS",
joinColumns = {@JoinColumn(name = "id")},
inverseJoinColumns = {@JoinColumn(name = "id")})
public List<ProductsDB> getProducts() {
return products;
}
...
ProductsDB.class
...
private List<OrdersDB> order = new ArrayList<>();
@ManyToMany
@JoinTable(name = "ORDER_PRODUCTS",
joinColumns = {@JoinColumn(name = "id")},
inverseJoinColumns = {@JoinColumn(name = "id")})
public List<OrdersDB> getOrder() {
return order;
}
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question