D
D
Dmitry Volokitin2021-02-11 16:08:35
Java
Dmitry Volokitin, 2021-02-11 16:08:35

Is there a need to bind entities in the DB if I bind them via spring data jpa in code?

I am writing a non-commercial application for myself. It is a normal work log.
There are columns:
the name of the transport, the names of the workers, the authorities, the name of the agent, the name of the customer.

I think the question is clear. Is it worth bothering and linking through table keys in sql, or can it be linked in the code itself through annotations? What are the consequences of such a connection? What are the nuances?

ps I'm a newbie, absorbing information.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2021-02-11
@Dima_gogi_ya

Good afternoon!

название транспорта, фамилии рабочих, инстанции, фамилия агента, фамилия заказчика.

Most likely, this should not be one table, but several, since these are different entities.
Those. The log can contain the user's entity (entities - agent, customer). And then using the OneToOne OneToMany ManyToOne ManyToMany connections, you need to connect these entities to each other.
Is it worth bothering and linking through table keys in sql, or can it be linked in the code itself through annotations?

The annotations will do this for you. In this case, you write according to the code first principle and, accordingly, all the logic for creating ddl should be in the code.
What are the consequences of such a connection?

Well, for example, incorrect setting of cascade types.
What are the nuances?

It will be difficult to retell the nuances given the generality of the issue. Read the documentation for Spring Data JPA and it will become clearer.

G
gsaw, 2021-02-11
@gsaw

If you mean whether you need constraints in the database, then no, not necessarily. They are needed to guarantee the integrity of the data in the database and as a means of documentation. While the program is working correctly, what they are, what they are not. At one point, your program or a third-party program will start writing garbage to the database, and with constraints you will catch it very quickly. Without them, everything will start to crumble, since JPA expects an associated object and there is null.
If you mean whether primary and third-party keys are needed in the tablets, then most likely yes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question