I think that the question you are asking is:
I load some objects from the database in a transaction. When I commit that transaction, some objects are saved back to the database. Why? How do I stop this?
Am I right? I'll answer that question anyway: if that's not what you are asking, can you try rephrasing the question and I'll try again.
The most likely explanation for this is that one (or more) of your mutators (set methods) does something "odd". For example:
Code:
public class Feature ...
{
...
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.oldName = this.name;
this.name = name;
}
...
}
Assuming that the oldName property is also in the Feature table, this code would cause objects of the Feature class to always be saved. When the object is loaded, it modifies itself so that it is no longer the same as the object in the database, and hibernate detects this and saves it when the session is flushed.
The solution is to eliminate code like this. A standard way to do this is to have different accessor/mutator (get/set) pairs for use by API users. For example:
Code:
public class Feature ...
{
...
public String getName()
{
return getInternalName();
}
public void setName(String name)
{
setOldName(getInternalName());
setInternalName(name);
}
public String getInternalName()
{
return this.name;
}
public void setInternalName(String name)
{
this.name = name;
}
...
}
Then you call the property "internalName" in your hibernate mapping file, but you use the getName() and setName() methods in java code. This avoids the problem.
Hope I've answered the right question. Post again, if I haven't.