What are JPA objects?

I am starting to use JPA and I am always confused with the term entities and their use, I read a lot, but I still do not quite understand. I read the Oracle documentation, but this does not really explain its role in the transaction.

What is a JPA? Do they really store data for each row, I mean, do they store instances containing row data? or do they just display the db tables and then insert and delete into them?

for example, if I use this:

entity.setUserName("michel"); 

Then save it, then change the username and write it down again (i.e. merge)

Does this change the previously entered username? or does it create a new line in db?

+4
source share
2 answers

An object is about the same as an instance of a class when you think about a code perspective or a row in a table (basically) when you think about a database perspective.

So this is essentially a persistent / persistent instance of the class. Changing the values ​​on it works the same way as changing the values ​​for any other instance of the class. The difference is that you can save these changes and, in general, the current state of the class (object) instance will overwrite the values ​​that the row for this instance (object) had in the database, based on the primary key in the database corresponding to "id "or a similar field in an instance of a class (entity).

Of course, there are exceptions to this behavior, but this is generally true.

+13
source

This is a model. This is a domain object that can be saved. Do not change your mind. Akin to the Rails model. And remember that models (in this paradigm) are mutable!

0
source

Source: https://habr.com/ru/post/1402330/


All Articles