public void persist (Object entity)
The Persist method can convert an instance to a managed (managed) state. After the flush () method is invoked or the object is submitted, the instance is inserted into the database.
A,persist of instances in different states will produce the following actions:
1. If a is an entity of a new state, it will be converted to a managed state;
2. If a is an entity with a managed state, its state will not change in any way. However, the system will still perform an insert operation on the database;
3. If a is a removed (delete) state entity, it will be converted to a controlled state;
4. If a is an detached (detached) State entity, the method throws a IllegalArgumentException exception, which is related to the different JPA implementations. public void merge (Object entity)
The main role of the merge method is to archive the user's modifications to a detached state entity, and a new managed state object will be created after the archive.
A,merge of instances in different states will produce the following actions:
1. If a is a detached state entity, the method submits a modification to the database and returns an instance of the new managed state A2;
2. If a is an entity of a new state, the method produces a managed state entity A2 based on A;
3. If a is an entity with a managed state, its state will not change in any way. However, the system will still perform an update operation on the database;
4. If a is an removed state entity, the method throws a IllegalArgumentException exception. public void Refresh (Object entity)
The Refresh method guarantees that the current instance is consistent with the contents of the instance in the database.
A,refresh of instances in different states will produce the following actions:
1. If a is an instance of a new state, no action occurs, but it is possible to throw an exception, depending on the different JPA implementations;
2. If a is an instance of a managed state, its properties will be synchronized with the data in the database;
3. If a is an instance of a removed state, no action will occur;
4. If a is an detached state entity, the method throws an exception. public void Remove (Object entity)
The Remove method can convert an entity to a removed state and delete the data in the database after calling the flush () method or submitting the object.
A,remove of instances in different states will produce the following actions:
1. If a is an instance of a new state, the state of a will not change, but the system will still execute the DELETE statement in the database;
2. If a is an instance of a managed state, its state is converted to removed;
3. If a is an instance of a removed state, no action will occur;
4. If a is an detached state entity, the method throws an exception.