@Autowired
private RoleGenerator roleGenerator;
@Test
public void identityShouldBePreserved() {
Role role = roleGenerator.getRole();
// add it to a Set before saving (force equals/hashcode)
Sets.newHashSet(role);
roleRepository.save(role);
entityManager.flush();
// reload it from cache and check equality
String id = role.getRole();
assertThat(role).isEqualTo(roleRepository.findOne(id));
// clear cache to force reload from db
entityManager.clear();