Answer the question
In order to leave comments, you need to log in
What is the correct way to annotate @OneToMany when using map in this case?
I have an Order and an Item, Order has an Item-Integer map (the product and how many times it was ordered). Unfortunately, I can't figure out how to properly place annotations over the map if my key is Entity.
Only the most important is listed here.
@Entity
public class Order {
@OneToMany(
mappedBy = "order",
cascade = CascadeType.ALL,
orphanRemoval = true)
private Map<Item, Integer> itemsQuantity = new HashMap<>();
}
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
public class Item {
private Order 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