Program: 2564
Project: 2564
Buggy source:
/** 
 * Test that after saving an entity with embedded object flush is correctly called if only the embedded entity is updated.  Causing bugs in non transactional read then a transactional write.
 */
@Test public void embeddedFieldOnlyDirty(){
  EntityManager em=entityManagerFactory.createEntityManager();
  em.getTransaction().begin();
  Customer james=new Customer();
  james.setEmail("String_Node_Str");
  james.setName("String_Node_Str");
  james.setPhoneNumber(new Phone("String_Node_Str",PhoneType.MOBILE));
  em.persist(james);
  em.getTransaction().commit();
  em.close();
  EntityManager em2=entityManagerFactory.createEntityManager();
  em2.getTransaction().begin();
  Customer returned=em2.find(Customer.class,james.getId());
  assertEquals(james,returned);
  assertEquals(james.getPhoneNumber(),returned.getPhoneNumber());
  assertEquals(james.getPhoneNumber().getPhoneNumber(),returned.getPhoneNumber().getPhoneNumber());
  assertEquals(james.getPhoneNumber().getType(),returned.getPhoneNumber().getType());
  em2.getTransaction().commit();
  returned.getPhoneNumber().setPhoneNumber("String_Node_Str");
  em2.getTransaction().begin();
  em2.persist(returned);
  em2.getTransaction().commit();
  em2.close();
  EntityManager em3=entityManagerFactory.createEntityManager();
  Customer returned2=em3.find(Customer.class,james.getId());
  assertEquals(returned,returned2);
  assertEquals(returned.getPhoneNumber(),returned2.getPhoneNumber());
  assertEquals(returned.getPhoneNumber().getPhoneNumber(),returned2.getPhoneNumber().getPhoneNumber());
  assertEquals(returned.getPhoneNumber().getType(),returned2.getPhoneNumber().getType());
}

Fixed version (ground truth):
/** 
 * Test that after saving an entity with embedded object flush is correctly called if only the embedded entity is updated.  Causing bugs in non transactional read then a transactional write.
 */
@Test public void embeddedFieldOnlyDirty(){
  EntityManager em=entityManagerFactory.createEntityManager();
  em.getTransaction().begin();
  Customer james=new Customer();
  james.setEmail("String_Node_Str");
  james.setName("String_Node_Str");
  james.setPhoneNumber(new Phone("String_Node_Str",PhoneType.MOBILE));
  em.persist(james);
  em.getTransaction().commit();
  em.close();
  EntityManager em2=entityManagerFactory.createEntityManager();
  em2.getTransaction().begin();
  Customer returned=em2.find(Customer.class,james.getId());
  em2.getTransaction().commit();
  assertEquals(james,returned);
  assertEquals(james.getPhoneNumber(),returned.getPhoneNumber());
  assertEquals(james.getPhoneNumber().getPhoneNumber(),returned.getPhoneNumber().getPhoneNumber());
  assertEquals(james.getPhoneNumber().getType(),returned.getPhoneNumber().getType());
  returned.getPhoneNumber().setPhoneNumber("String_Node_Str");
  em2.getTransaction().begin();
  em2.persist(returned);
  em2.getTransaction().commit();
  em2.close();
  EntityManager em3=entityManagerFactory.createEntityManager();
  Customer returned2=em3.find(Customer.class,james.getId());
  assertEquals(returned,returned2);
  assertEquals(returned.getPhoneNumber(),returned2.getPhoneNumber());
  assertEquals(returned.getPhoneNumber().getPhoneNumber(),returned2.getPhoneNumber().getPhoneNumber());
  assertEquals(returned.getPhoneNumber().getType(),returned2.getPhoneNumber().getType());
}