Hi there,
I am trying to figure out what should happen if I modify an entity marked
as @Immutable. Somehow I expected an exception to be raised, but nothing
seem to happen. I wrote this test case (the Country entity is marked as
@Immutable):
public void testImmutableEntity() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Country country = new Country();
country.setName("Germany");
s.persist(country);
tx.commit();
s.close();
try {
s = openSession();
tx = s.beginTransaction();
Country germany = (Country) s.get(Country.class, country.getId());
assertNotNull(germany);
germany.setName("France");
s.save(germany);
// s.delete(germany);
tx.commit();
s.close();
fail();
} catch (Exception e) {
log.debug("success");
}
}
The exception is never raised. The core documentation only says "Immutable
classes may not be updated or deleted by the application". It does not say
anything about what happens if one tries to do so. Should the above
testcase work or not?
Thanks,
Hardy