Dynamic Update with JPA

I was surprised to learn that the default behavior in sleep mode is to update all fields in an object if only one change is made and merge is called.

Dynamic update is a field that allows you to configure an alternative approach only to update a changed field ...

http://www.mkyong.com/hibernate/hibernate-dynamic-update-attribute-example/

I am using jpa with hibernate and i tried adding the following

@javax.persistence.Entity
@org.hibernate.annotations.Entity(dynamicInsert=true, dynamicUpdate=true) 

for my class (previously it had only JPA annotation)

Anyway, I controlled sql and, unfortunately, it did not change it, and I still see that each field is updated.

This is my java that updates the object ...

    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)    
public void setAccountStatusForUser(String username, AccountStatus act){
    User u = this.getUser(username);
    u.setAccountStatus(act);
    this.update(u);
}

and the update method does the following:

    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
  public Object update(Object o) {
      Object a = this.entityManager.merge(o);
      this.entityManager.flush();
      return a;
}

Any help would be greatly appreciated.

+5
3

, :

  • getUser()?
  • ?
  • ?

- , . - , .

Springsource Forum, , select-before-update ​​ true, Hibernate . select-before-update .

User , ...

0

:

@javax.persistence.Entity, . @org.hibernate.annotations.Entity .

0

You attach a separate object through a call to merger (). In this case, you must include selectBeforeUpdate. This is in javadocs.

0
source

All Articles