}
@Test
public void shouldSaveEntitiesWhenThePartitionKeyChanges() throws Exception {
DataAccessObject<WeatherReport, Integer> dao = new ErrorCorrectingDataAccessObject<WeatherReport, Integer>(WeatherReport.class, getEntityHiveConfig().getEntityConfig(WeatherReport.class),getHive(), getSessionFactory());
WeatherReport report = getPersistentInstance(dao);
String oldContinent = report.getContinent();
String newContinent = report.getContinent().equals("Asia") ? "Australia" : "Asia";
report.setContinent(newContinent);
dao.save(report);
Session oldNodeSession = null;
Session newNodeSession = null;
try {
oldNodeSession = hiveSessionFactory.openSession(oldContinent);
newNodeSession = hiveSessionFactory.openSession(newContinent);
if(!hive.directory().getNodeIdsOfPrimaryIndexKey(oldContinent).equals(hive.directory().getNodeIdsOfPrimaryIndexKey(newContinent)))
assertNull(oldNodeSession.get(WeatherReport.class, report.getReportId()));
WeatherReport fetched = (WeatherReport) newNodeSession.get(WeatherReport.class, report.getReportId());
assertNotNull(fetched);
assertEquals(newContinent, fetched.getContinent());
} finally {
if(oldNodeSession != null)
oldNodeSession.close();
if(newNodeSession != null)
newNodeSession.close();