What happens if you remove the unecessary save() call after changing the
name?
On Mon, 2008-06-23 at 09:08 +0200, Hardy Ferentschik wrote:
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
_______________________________________________
hibernate-dev mailing list
hibernate-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev