Answer the question
In order to leave comments, you need to log in
In what form is it better to store the Entity order - the amount ordered?
For example, there is an Entity Order, from which I must find out the item and how many pieces were ordered.
But what is the best way to store it?
@OneToMany
List itemList
Or via HashMap.
Map
I would be grateful to hear a typical solution for such tasks and why.
Answer the question
In order to leave comments, you need to log in
There are not enough details in the question. What base is supposed to actually store this entity ? If this is a classic relational, then in my opinion it is better to store it as a List or Set. Potentially, Map could make it possible to access an order element by its number (or some key) in O(1) time (i.e., in constant time). This would give a win in the case of very large orders with a large number of elements. But since the base actually stores the value, then if you need to search for one element without pulling the entire list into memory, this can be done by selecting by index. (for example, order id + element id or just a "through" element id) If orders do not exceed 10-50 elements, then there is no point in bothering at all and you should choose the simplest method, i.e. List. Already in the code itself, you can arrange access to this field as you like. Due to the small size of the list, there should be no performance issues.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question