Pradeep (3) [Avatar] Offline
#1
I am reading the section on dirty checking from the section 3.2.3 and have a doubt from the below quote
Another issue to consider is dirty checking. Hibernate automatically detects state changes in order to synchronize the updated state with the database. It’s usually safe to return a different instance from the getter method than the instance passed by Hibernate to the setter. Hibernate compares them by value—not by object identity—to determine whether the attribute’s persistent state needs to be updated. For example, the following getter method doesn’t result in unnecessary SQL UPDATEs:

public String getFirstName(){
    return new String(firstName);
}


My question is why returning a new String object will not make unecessary SQL UPDATEs and how is it different from returning just the firstName ?