This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14474|Reply: 0

[Source] In Spring boot, the JPA persistent listener intercepts additions, deletions, and modifications

[Copy link]
Posted on 4/2/2019 4:20:47 PM | | |
In JPA, we use the Java Persistence API to persist data (adding, deleting, modifying, and checking), which also provides a callback method in the life cycle of listening to data persistence, which is mainly implemented by the following annotations:

* @PrePersist Before saving
* @PostPersist After saving
* @PreRemove before deletion
* @PostRemove after deletion
* @PreUpdate Before the update
* @PostUpdate After the update
* After @PostLoad query

These annotations must be used in conjunction with @EntityListeners annotations, @EntityListeners annotations are entity listener annotations.

Let's take the Saving Customer object as an example:

Step 1: Create a listener class CustomerListener

Step 2: Add @EntityListeners annotation to the Customer class

Through the above, data persistence can be intercepted.





Previous:Introduction and mastery of quantitative investing
Next:3 ways to get class names in Java!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com