我们如何才能获得JPA EntityManager Flush工作 [英] how we can get JPA EntityManager Flush work

查看:144
本文介绍了我们如何才能获得JPA EntityManager Flush工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是为什么flush不起作用:

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");
}

完成方法后,我在db
中看到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屋!

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