Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

em.getTransaction().commit();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...