我的问题是为什么冲洗不起作用:
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");
}
完成方法后,我在db中看到“anotherName” 我也用em.find(Customer.class,1,Lock.None)检查它;但仍然没有工作
RGDS
答案 0 :(得分:23)
您正在刷新,但您没有提交 - 或以其他方式结束可能已配置为自动提交的事务/会话。
是的,在调用flush()
之后,DBMS现在知道您的数据了 - 但是遵循ACID标准,在DBMS被告知提交之前,没有其他数据库会话会看到这些数据。
如果不了解有关其他应用程序背后的架构的其他详细信息,您可能希望执行以下操作:
em.getTransaction().commit();