EntityManager.refresh() loses changes that have been flushed.
The following code results in loss of changes made before em.flush() at (b) in B47. The application is deployed as EAR, ie. the code is executed inside of GlassFish.
@PersistenceContext(EXTENDED) EntityManager em;
MyEntity myEntity = em.find(MyEntity.class, id);
em.refresh(myEntity); // Maybe not neccesary, but I needed it for the app. to work with B36.
// Here, myEntity.getMemo() is null.
myEntity.setMemo("Hi, it's new memo");
// Here, myEntity.getMemo() is "Hi, it's new memo"
em.flush(); // (a)
em.refresh(myEntity); // (b)
// Here, myEntity.getMemo() is null, not "Hi, it's new memo"
// If you comment out (b), you will get "Hi, it's new memo" here.
The property "memo" is a simple String persistent property. Any attempt to access myEntity.getMemo() result in 'null' after (b). The MEMO column in the database is left unchanged. Changes made (a) is completely lost.
When I was using B36, I had this problem too. But (a) and (b) were not there. They were added to avoid the probelm in B36. Now, (b) causes the problem.
Any help is appreciated.