On my existing application, I have a logging system that tracks changes to data objects and logs them.
When my business layer's update method is called, I load the original contents from the database and make a comparison like so:
Code:
public void update(Group group)
{
Group original = groupDAO.get(group.getId());
log.info(SECTION_NAME, "Update", "Changes:\n"
+ BeanTool.diff(original, group, "\n", ignoreProperties)
+ "\n------------------------------\nOriginal:\n"
+ BeanTool.makeString(original, "\n", ignoreProperties));
// We have to do this because the object just loaded from the DB is the
// one attached to the hibernate session.
BeanTool.copyProperties(group, original);
groupDAO.update(original);
}
Where groupDAO operates like so:
Code:
public Group get(int id)
{
return (Group)getHibernateTemplate().get(Group.class,
new Integer(id));
}
public void update(Group group)
{
getHibernateTemplate().update(group);
}
When I upgraded Hibernate from 3.0.5 to 3.1.3, this stopped working.
Now, if I try to load the database copy, Hibernate simply gives me back the one I've already changed, even though I haven't actually written it to the database.
This gets even worse in other areas, where a user makes some changes (which I write to the object) but then clicks cancel on one of the pages.
Even though I haven't saved it to the database, hibernate keeps giving back the modified object on subsequent loads instead of what's actually stored in the database.
Is this a bug?
A feature?
If so, how do I turn it off?