B
B
Biaci_Anj2022-02-06 16:44:59
Java
Biaci_Anj, 2022-02-06 16:44:59

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

1 answer(s)
O
Orkhan, 2022-02-06
Hasanly @azerphoenix

Good afternoon.
Here is a visual article on your question:
https://www.baeldung.com/hibernate-persisting-maps

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question