SPRINGDATAJPA Entity Overview
JPA provides a simple and efficient way to manage the mapping of Java Objects (POJO) to relational databases, which become JPA entities or short entities. Entities are typically associated with a single relational table in the underlying database, and an instance of each entity represents a row in a database table
SPRINGDATAJPA Entity Manager
The Entity Manager (Entitymanager) is used to manage entities in the system, which is a bridge between the entity and the database, which can be persisted into the database by invoking the relevant method of the entity manager, and the records in the database can be packaged into entity objects.
The life cycle of an entity:
As we can see, there are four states of an entity: New state, managed state, Free State, delete state.
A newly created object is in a new state, like creating a normal Java object, is a new object through the new object, after the creation of an assignment to the Entity manager's Persist method, you can let the entity State migration to the managed state, There are two things you can do at this time: INSERT statements insert data into the database and Mark entities as managed, and entities that are in the managed state are automatically committed to the database after the transaction commits if the property is modified. The managed state signifies being managed by the entity manager, and if we commit the transaction, then the state of the entity becomes Free State.
The so-called Free State, refers to the modification of the entity's properties will not trigger the database operation, this state is similar to the new state, the difference is that the Free State of the entity ID attribute is a value, and the entity ID of the new state is not a value. If you invoke the Close method of the entity manager or the clear method or detach, you can make the entity a Free State. Where the Close method is to close the entity manager, the clear method is that all entities of the Entity manager become free states, and detach can turn a single entity into a Free state. Entities that are in the managed state we can delete and can invoke the Remove method of the entity manager. But this time the system will not actually delete the data, the need to commit a transaction to delete the record.
SPRINGDATAJPA Getting Started 2