Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

For example, consider 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 (that's my "impression" of Hibernate) that when working with a standard Hibernate mapping (mapping the full class), even updates of only a single member lead to a full update of the object in the 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 quite some work on dirty-checking, but as far as I know this dirty checking is only relevant to identify if the object as whole is dirty, not what single member is dirty.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
476 views
Welcome To Ask or Share your Answers For Others

1 Answer

Actually, you can specify the options dynamic-update and dynamic-insert in a class mapping. It does just that. More info here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...