Under what circumstances are transactions necessary? I have a Customer object with a Map as an instance variable. Modifications to the map are written to the database iff I'm using transactions--is this supposed to happen?
In the following code, the attribute-value pair "COLOUR"/"BLUE" is written to the database iff the tx.commit() line is present--without it, it's not (and not error or Exception is raised).
I'm using Hibernate 2.1 and MySQL 4.0.18.
Code:
public void testStrange() throws Exception {
Customer c = new Customer();
Map m = c.getAttribute();
m.put("COLOUR", "BLUE");
Session s = dowcarter.Util.getSession();
s.save(c);
try {
Transaction tx = null;
tx = s.beginTransaction();
tx.commit();
}
catch (Exception e) {
System.out.println(e);
}
s.close();
}