Beans in cache can be changed without persistence
-------------------------------------------------
Key: IBATIS-251
URL: http://issues.apache.org/jira/browse/IBATIS-251
Project: iBatis for Java
Type: Bug
Components: SQL Maps
Versions: 2.1.6
Environment: Resin 3/Linux/Spring
Reporter: Reuben Firmin
The following code illustrates the problem:
Foo foo1 = dao.getFoo(fooId);
foo1.setBah(true);
try {
dao.updateFoo(foo1);
} catch (Exception e) {
Foo foo2 = dao.getFoo(fooId);
if (foo2.getBah())
System.err.println("The bug!");
}
Assume the dao method throws an exception due to validation failure, prior to
any calls being made to the database.
The problem is that because a reference foo1 is obtained from the dao (which
uses the built in caching), we are now pointing to the same bean that is in the
cache. So, even if we don't persist foo1 to the database, the cached copy of
foo1 contains the mutated properties; system wide, our change is instantly
propagated. This is IMO a pretty serious issue.
A fix would be to make the cache return cloned beans, or have the cache build
new beans based on the setter/getter properties; or similar. In any case, the
desired effect is that the bean that the cache references NOT be mutatable by
the rest of the system.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira