While working on a team side project, we were talking about the reason for using JPA (ORM).
One person agonized over the meaning of persist and permanence, and started talking.
Persistence The dictionary meaning is to continue.
There is a persist() method of entity manager. You could say save.
The reason may be up to definition, but I simply have flush and commit steps,
He said that it would have been named persist() because it is made persistent in the persistence context.
This is because save includes persist, flush, and commit.
The team member's idea was a little further.
I said persist the object in the persistence context.
It meant that it was a context that managed objects.
I had the following question.
I couldn't explain it, so I looked it up in the dictionary, and it had the same meaning as something lasting or eternal.
It's something everyone knows about by feel.
Here, he conveyed his thoughts on why JPA uses the concept of persistence called persistence.
The reason is?
What do you mean in the first place? I thought.
But I became more and more sympathetic.
Java exists in the world of JVM. That is, it cannot persist outside the JVM.
When the JVM disappears, the java object also disappears. But JPA wanted to keep it outside of the JVM.
So, the concept of persistence came out with the idea of wanting to persist objects that existed in the JVM outside the JVM.
It could be a database or a text file. The important thing is that you want to persist the object outside the JVM.
Here I have a question.
I want to persist an object outside the JVM. That is, it is stored in the database after all.
Even if you do not use JPA and use MyBatis, you can persist objects in a database outside the JVM.
However, the reason why persist means persistence is used only in JPA is as follows.
MyBatis is just a database mapper object with no object oriented thinking.
Of course, persisting objects in a database outside the JVM is correct, but the paradigm itself is different.
The key is that you don't want to keep the object externally, you want to map it to the database.
On the other hand, JPA is not the main database. It is designed to be object-oriented and less affected by the database.
That is, you want to persist the object to the outside world. To summarize, if MyBatis is DB → object, JPA is the same concept as object → DB.
That's why JPA uses persistent semantics, and MyBatis doesn't.
This content is the content discussed in the hibernate official document,
Why ORM should be used → Why did JPA pursue ORM among ORMs → Why JPA uses the meaning of persistence
It is a story that comes from the flow of thoughts. It may not be the right answer, but the most important thing in using technology is
I think that's why this technology was born. This is because it can be used well in the background.
Otherwise, using it incorrectly, you get the absurd idea that this technology is bad.
In this conversation, it seems that I came a little closer to the philosophy that JPA pursues, and this experience is a little bit of a way to properly use the technology.
I think it will be of great help.
Have you been too focused on the technical part so far? It was a conversation that made me think a little bit.