JPA刷新与提交 [英] JPA flush vs commit

查看:258
本文介绍了JPA刷新与提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JPA中,如果我们调用EntityTransaction.commit(),它会自动调用EntityManager.flush()吗?还是我们都应该称呼它们?有什么区别?因为我在使用JPA时遇到问题,所以当我向数据库中插入实体时,我会调用persist().在数据库中,数据已插入(可以获取),但是该数据未显示在我的应用程序中(我使用findAll()进行获取).在另一个实体上,它出现了.有我不知道的东西吗?我正在使用标准的Spring CRUD,JPA resource_local和postgresql.对不起,我的英语,谢谢您.

in JPA, if we call EntityTransaction.commit(), does it automatically call EntityManager.flush()? or should we call them both? what is the difference? because i have problem with JPA, when i insert an entity to database, i call persist(). in the database, the data has been inserted (can be fetched), but that data doesn't show up in my app (i fetch it using findAll()). and on another entity, it showed up. is there something i don't know? i'm using standard Spring CRUD, JPA resource_local, and postgresql. sorry for my english, thanks in advance

推荐答案

如果我们调用EntityTransaction.commit(),它会自动调用吗 EntityManager.flush()?

if we call EntityTransaction.commit(), does it automatically call EntityManager.flush()?

有什么区别?

what is the difference?

在flush()中,遇到刷新后,对数据的更改会反映在数据库中,但仍保留在transaction.flush()中必须将其包含在事务上下文中,除非有必要,否则不必显式进行操作( (在极少数情况下),当EntityTransaction.commit()为您做到这一点时.

In flush() the changes to the data are reflected in database after encountering flush, but it is still in transaction.flush() MUST be enclosed in a transaction context and you don't have to do it explicitly unless needed (in rare cases), when EntityTransaction.commit() does that for you.

来源

这篇关于JPA刷新与提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆