M
M
mitaichik2018-03-05 15:56:25
Java
mitaichik, 2018-03-05 15:56:25

Spring: How to organize that the object from the database is in a single copy?

Hello! New to java/spring.
In general, there is an entity stored in mongodb. The entity is selected only by ID. I want to have some manager who would manage it in the following way:
- when trying to get an entity by id, it looked to see if this entity was loaded earlier. If yes, I would give the same instance as in the previous request, if not, I would select from the database.
- the manager had the opportunity to save it in the database.
- (preferably) the manager would unload it from memory if, for example, there were no requests for it within 20 minutes.
- (preferably) the manager himself could understand that the entity has changed and the changes need to be dumped into the database
. Do I understand correctly that JPA just offers something similar, or are there any other mechanisms for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2018-03-05
@mitaichik

Yes, in general, you understand everything correctly. Except for the last one - records when the entity has changed. Here you still need to tell the "manager" explicitly so that he throws the entity into the database if it has changed. This is done in the name of data security, when we changed the entity, and the "manager" needs to know that the data can already be dumped and is consistent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question