entityManager.flush();
}
@Test
public void primaryKeyUnmodifiedAfterUpdate() {
Installation android1 = new Installation();
android1.setAlias("foo@bar.org");
android1.setDeviceToken(DEVICE_TOKEN_1);
android1.setDeviceType("Android Phone");
final Set<Category> categoriesOne = new HashSet<Category>();
final Category category = entityManager.createQuery("from Category where name = :name", Category.class)
.setParameter("name", "soccer").getSingleResult();
categoriesOne.add(category);
android1.setCategories(categoriesOne);
final String id = android1.getId();
final AndroidVariant variant = new AndroidVariant();
variant.setGoogleKey("12");
variant.setProjectNumber("12");
entityManager.persist(variant);
android1.setVariant(variant);
installationDao.create(android1);
// flush to be sure that it's in the database
entityManager.flush();
// clear the cache otherwise finding the entity will not perform a select but get the entity from cache
entityManager.clear();
Installation installation = installationDao.find(id);
assertThat(installation.getId()).isEqualTo(id);
assertThat(installation.getDeviceType()).isEqualTo("Android Phone");
final String alias = "foobar@bar.org";
android1.setAlias(alias);
installationDao.update(android1);
entityManager.flush();
entityManager.clear();
installation = installationDao.find(id);
assertThat(installation.getAlias()).isEqualTo(alias);
}