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

View: 16200|Reply: 0

[Source] The difference between Spring JPA save and saveAndFlush

[Copy link]
Posted on 4/1/2019 4:39:22 PM | | |
On saveAndFlush, the changes in this command are immediately refreshed to the DB. With save, this is not necessarily true and may only remain in memory until a flush or commit command is issued.

Note, however, that even if you refresh the changes in a transaction and don't commit them, the changes are still not visible to the external transaction until they are committed in this transaction.

In your case, you may be using some kind of transaction mechanism that will issue you a commit command if everything is fine.

Use the JPA saveAndFlush() method

Implement Increase and Modify

Note: The control layer needs to filter parameters,

saveAndFlush This method first determines whether to use the persist method or the merge method based on ID==null
It will decide whether to use insert or update based on whether the ID is recorded in the database

We look at the difference by decompiling the Java source code

IDEA_ shortcut to find the implementation of the interface

IDEA style ctrl + alt +B

Eclipse style ctrl +T


Save Interface:

Implementation method:

saveAndFlush interface:
Implementation method:

As you can see from the source code, calling the saveAndFlush method,saveAndFlush calls our save method and then the flush method

(End)





Previous:Command line is too long. Shorten command line for itsvse or also for...
Next:Use Nginx Reverse Proxy and Content Replacement Module to implement dynamic web content replacement
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