Scene:
Now, one of the things that is provided in the service is to remove all eligible data before inserting all new conditions into the database
This scenario requires a two-step implementation of the service
1. Delete
2. Insert
These two steps are naturally done in the same transaction, which is a complete operation.
So for this scenario, let's see how the annotations work.
1 "First look at the DAO layer link: http://www.cnblogs.com/sxdcgaq8080/p/8984140.html
The DAO layer is also the delete operation of the repository layer, which is the use of the delete operation in JPA, which needs to be added
@Modifying
@Transactional
These two annotations, because
[Email protected] to notify Springdata that this is an UPDATE or DELETE operation
The 2.UPDATE or delete operation requires a transaction, so you need to add these two annotations to the DAO layer's Delete method
2 "and then said the service layer of this method in two steps to go
Needs to be added to the entry method.
@Transactional
Annotations to ensure that two-step operations are performed within the same transaction
In this case, the first transaction annotation worked, and the annotation on the Delete method was added to support the delete operation.
When spring data JPA uses spring data JPA, the "delete" and "insert" operations in one method of the service layer are processed within the same transaction