我们如何让 JPA EntityManager Flush 工作
我的问题是为什么刷新不起作用:
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); 检查它 仍然不起作用
但RGDS
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");
}
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在刷新,但您没有提交 - 或者以其他方式结束可能配置为自动提交的事务/会话。
是的,在调用
flush()
之后,DBMS 现在知道您的数据 - 但遵循 ACID 标准,在 DBMS 被告知提交该数据之前,其他数据库会话都不会看到该数据。在不了解应用程序其余部分背后的架构的其他详细信息的情况下,您可能希望执行以下操作:
You're flushing, but you're not committing - or otherwise ending the transaction / session which is likely configured for auto-commit.
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: