我们如何让 JPA EntityManager Flush 工作 [英] how we can get JPA EntityManager Flush work
问题描述
我的问题是为什么冲洗不起作用:
my question is why flush doesn't work :
public void ejbService(){
Customer c = em.find(Customer.class,1);
c.setName("newName");
em.flush();
//at this point when I query mysql table I can not see "newName"
thread.sleep(10000);
c.setName("anotherName");
}
完成该方法后,我在数据库中看到anotherName"我也用 em.find(Customer.class,1,Lock.None);但还是不行
After finishing the method I see "anotherName" in the db also I check it with em.find(Customer.class,1,Lock.None); but still not work
RGDS
推荐答案
您正在刷新,但没有提交 - 或者以其他方式结束可能配置为自动提交的事务/会话.
You're flushing, but you're not committing - or otherwise ending the transaction / session which is likely configured for auto-commit.
是的,在调用 flush()
之后,DBMS 现在知道您的数据 - 但按照 ACID 标准,在 DBMS 被告知提交数据之前,其他数据库会话都不会看到这些数据.
Yes, after calling flush()
, the DBMS is now aware of your data - but following ACID standards, no other database sessions will see this data until the DBMS is told to commit it.
在不了解应用程序其余部分背后架构的其他详细信息的情况下,您可能希望执行以下操作:
Without knowing additional details about the architecture behind the rest of your application, etc., you're probably looking to do something like:
em.getTransaction().commit();
这篇关于我们如何让 JPA EntityManager Flush 工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!