}
@Test
public void testUpdateFail() throws Exception {
HiveSessionFactoryBuilderImpl factoryBuilder = getHiveSessionFactoryBuilder();
final WeatherReport report = newInstance();
SessionCallback callback = new SessionCallback(){
public void execute(Session session) {
session.saveOrUpdate(report);
}};
doInTransaction(callback, factoryBuilder.openSession());
final WeatherReport mutated = newInstance();
//System.err.println(((WeatherReport) factoryBuilder.openSession().get(getGeneratedClass(WeatherReport.class), report.getReportId())).getWeatherEvents().size());
GeneratedInstanceInterceptor.setProperty(mutated, "reportId", report.getReportId());
GeneratedInstanceInterceptor.setProperty(mutated, "continent", report.getContinent());
GeneratedInstanceInterceptor.setProperty(mutated, "temperature", report.getTemperature());
GeneratedInstanceInterceptor.setProperty(mutated, "reportTime", new Date(System.currentTimeMillis()));
// Updating collection items requires more advanced persistence login (see BaseDataAccessObject)
// so we leave these values identical
GeneratedInstanceInterceptor.setProperty(mutated, "weatherEvents", report.getWeatherEvents());
GeneratedInstanceInterceptor.setProperty(mutated, "sources", report.getSources());
assertTrue(
"You have to change something if you want to test update.",
ReflectionTools.getDifferingFields(report, mutated, WeatherReport.class).size() != 0);
SessionCallback updateCallback = new SessionCallback(){
public void execute(Session session) {
session.saveOrUpdate(mutated);
}};
doInTransactionAndFailBeforeCommit(updateCallback, factoryBuilder.openSession());
WeatherReport fetched = (WeatherReport) factoryBuilder.openSession().get(getGeneratedClass(WeatherReport.class), report.getReportId());
assertNotNull(fetched);
assertEquals(ReflectionTools.getDifferingFields(report, fetched, WeatherReport.class).toString(), report, fetched);
Assert.assertFalse(ReflectionTools.getDifferingFields(mutated, fetched, WeatherReport.class).size() == 0);
}