@Autowired
private AccountGenerator accountGenerator;
@Test
public void identityShouldBePreserved() {
Account account = accountGenerator.getAccount();
// add it to a Set before saving (force equals/hashcode)
Sets.newHashSet(account);
accountRepository.save(account);
entityManager.flush();
// reload it from cache and check equality
Integer id = account.getIdAccount();
assertThat(account).isEqualTo(accountRepository.findOne(id));
// clear cache to force reload from db
entityManager.clear();
// pk are equals...
assertThat(account.getId()).isEqualTo(accountRepository.findOne(id).getId());
// but since you do not use a business key, equality is lost.
assertThat(account).isNotEqualTo(accountRepository.findOne(id));
}