Spring数据jpa中save和saveAndFlush的区别 [英] Difference between save and saveAndFlush in Spring data jpa
问题描述
我试图通过 JpaRepository
来测试一些CRUD操作来学习Spring数据。
保存
和 saveAndFlush
。 我没有得到这两者之间的区别。在调用
save
时,我的更改也被保存到数据库中,因此 saveAndFlush
的用处。在 在你的情况中,你可能使用某种事务机制,它为你发出 I am trying to learn spring data JPA by testing some CRUD operation via I came across two methods On But be aware, that even if you flush the changes in transaction and do not commit them, the changes still won't be visible to the outside transactions until the commit in this transaction. In your case, you probably use some sort of transactions mechanism, which issues 这篇关于Spring数据jpa中save和saveAndFlush的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! saveAndFlush
上,更改将立即在此命令中刷新到DB。使用 save
,这不一定是真实的,并且可能会保留在内存中,直到 flush 或
commit
命令被发出。但请注意,即使您在事务中刷新了更改并且未提交它们,但这些更改对于外部事务仍然不可见,直到提交这个事务。
commit
命令如果一切正常的话。JpaRepository
.save
and saveAndFlush
.
I don't get the difference between these two. On calling save
also my changes are getting saved into database so what is the use of saveAndFlush
.saveAndFlush
, changes will be flushed to DB immediately in this command. With save
, this is not necessarily true, and might stay just in memory, until flush
or commit
commands are issued. commit
command for you if everything works out fine.