I have Order
entity, each order has a list of Dish
entity.
Only important part showed for brevity.
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Table(name = "orders")
@ToString
public class Order {
@OnDelete(action = OnDeleteAction.CASCADE)
@OneToMany(
mappedBy = "order",
cascade = CascadeType.ALL,
orphanRemoval = true)
@ToString.Exclude
private List<Dish> dishes;
}
My front sends me a Hashmap
of dish.id
and quantity of this dish ordered.
To convert it to Order entity I have to add the same dish to list times it was ordered. For example. if order has 5 dishes of id 1, I fetch id 1 and add it 5 times to list, then - save order.
To display this again in front - I use Collections.frequency to convert the Order back to Hashmap.
Should I convert my relationship container to hashmap? I've heard that I should avoid using hashmaps in Hibernate.