Hibernate: Dirty Checking and Only Update of Dirty Attributes?

Posted by jens on Stack Overflow See other posts from Stack Overflow or by jens
Published on 2010-04-20T11:08:44Z Indexed on 2010/04/20 11:13 UTC
Read the original article Hit count: 425

Filed under:
|

Hello Experts,

in "good old JDBC days" I wrote a lot of SQL Queries that did very targeted updates of only the "attributes/members" that were actually changed:

For Example having an object with the following members:

public String name;
public String address;
public Date date;

If only date was changed in some Business Method I would only issue an SQL UPDATE for the date member.

==>It seems however (thats my "impression" of hibernate) that when working with a standard Hibernate mapping (mapping the full class), even updates of only one single member lead to a full update of the object in SQL Statements generated by Hibernate.

My Questions are:

1.) Is this observation correct, that hibernate DOES NOT intelligently check (in a fully mapped class), what member(s) where changed and then only issue updates for the specific changed members, but rather always will update (in the generated SQL Update Statement) all mapped members (of a class), even if they were not changed (in case the object is dirty due to one member being dirty...)

2.) What can I do to make Hibernate only update those members, that have been changed? I am searching for a solution to have hibernate only update the member that actually changed.

(I know hibernate does some big work on doing dirty-checking, but as far as I know this dirtychecking is only relevant to identify if the object as whole is dirty, not what single member is dirty.)

Thank you very much! Jens

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about java