我们如何才能获得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"); } 

完成方法后,我在db中看到“anotherName”,我也用em.find(Customer.class,1,Lock.None)检查它; 但仍然没有奏效

RGDS

你正在刷新,但你没有提交 – 或以其他方式结束可能配置为自动提交的事务/会话。

是的,在调用flush() ,DBMS现在知道您的数据 – 但是遵循ACID标准,在DBMS被告知提交之前,其他任何数据库会话都不会看到此数据。

如果不了解其他应用程序背后的架构的其他详细信息,您可能希望执行以下操作:

 em.getTransaction().commit();