I'm trying to update one column of a table using hibernate but I can not prevent the operation from overriding the entire table record. I have tried different options based on searches I've done on google and I just don't know what I'm missing. Can someone help me?
This is what I have so far:
Here is a snippet of my hibernate config file for the "detail" table:
Here is the snippet of my Controller that processes the form:
So when I test the form it hits the mergeDetail method since the record already exists....
I understand that I could probably just pass the column I'm interested in changing instead of the entire Detail object. However, I'm doing this dynamically in which the jsp form where I define the "path" is not really hardcoded with the "summary" column. Instead I'm actually passing a variable in it's place so I don't have a handful of jsp forms, I can just use the same form and just change the path value.
Basically, you have a detached object, and when you merge it back into Hibernate, Hibernate doesn't know what you changed, so it has to assume it is all changed. That is why the dynamic-update isn't working as you expected.
To see what I mean, write a test that creates a Session, loads one record. Change one property of your class, then flush and notice that the update statement only has the changed field.
In another test method. Load one record in a Session. Close the session. Change one property of your class, create a new Session then merge the object into that session then flush and now the update statement will have all the fields.
The only way to not have this is to manually write your update statement as SQL and run that through the Session object. (There is an obscure byte code instrumentation for something else, that will add an update flag to your object, but even that will include all the fields)