C
C
Crunchor2021-03-02 11:57:29
Hibernate
Crunchor, 2021-03-02 11:57:29

How to properly organize the sample?

Initial data:
Table person
id | firstname | last name | birthdate ...

Table order
id | product_id | count | price | person_id ...

Table product
id | name | price ...

(The tables are fictitious, they are only needed to describe the situation)
The project has entities (Entity) for each table with foreign keys and relationships.

I need to get a table / object in which there will be data from each of these tables. For example something like this...
order.id | product.name | order.count | person.firstname | ...
How to me it is more correct to implement it?
2 options come to mind:
1. Create a view in the database that will collect all the necessary data in one table. In this case, you will have to create a new
Entity, services and repositories, etc.
2. In the OrderService, get all the necessary records by separate requests to each entity. If there is
a lot of such data (> 100,000), then this is a huge number of queries to the database for the sake of one result. The question also arises as to how I can
get all orders, for example, in which the person is under 18 years old.

Which of these options is more correct or are they both wrong and there are some other, more correct options? Maybe someone has links to github, where there are implementations of such tasks?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2021-03-02
@Crunkor

Actually, from the user's point of view, it will be correct to display information on the screen 200-300ms after pressing the button)
item 1 is a little closer to this, but it's worth looking towards the stored procedure with filtering, ordering, etc. parameters. and already from this entity to dance, so that you can receive, among other things, once the top 10 orders from minors, and the other - a list of orders from minors from the category of excisable goods ... the third time the same for the period, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question