D
D
DeNissss44442021-05-26 11:39:01
Java
DeNissss4444, 2021-05-26 11:39:01

How to pass an object from one repository to another in Spring?

I have two repositories. In the first one, I have candidates for a coach, and in the second, already a coach. I want to make sure that the admin has the opportunity to press the confirm button and the candidate becomes a coach. I understand that for this it is necessary that the candidate object, after pressing the key, passes from the candidate repository to the trainer repository. And now the logical question arises how to transfer an object from one repository to another in Spring?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2021-05-26
@DeNissss4444

Good afternoon!
As a colleague Dmitry Roo noted :

In general, it seems to me that your architecture is not very well thought out.
It would be better to make separate users and separate roles.

In this case, I agree with him. It is better, of course, to simply have the User entity, but at the same time have an enum Role (for example, candidate_trainer, trainer). And then when you click on the button in the admin panel, you simply change the user role from candidate_trainer -> trainer and that's it.
It is possible that there are reasons why you decided to separate the entity data. Then just delete the old record and create a new one.
For example,
when clicking, we take the Id of the candidate.
We find it by id.
Create a new entity (you can even write some Converter<S, T>)
Save a new entry
Delete the old entry

D
Dmitry Roo, 2021-05-26
@xez

You don't have to transfer anything.
You create a new object.
Delete the old one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question