Can Hibernate update a single property?

I have a hibernation class with more than one property, I heard that NHibernate keeps track of properties in files and updates only those properties that have been changed. Are there any similar features in Hibernate?

I tried to get it to work with a simple class load, and then set one property - then discard the changes. However, this necessarily updates all the properties in the class.

+3
source share
2 answers

You need to set the dynamic-update property to true using the annotation or in a class mapping that excludes unmodified properties in the Hibernates SQL update statement. Here you can find a good link here . By default, dynamic updates are set to false to be backward compatible, as this is a slightly new feature.

+4
source

First you can get Entity from db and then upgrade ... try this example.

public final void updateEntity(EntityName entity){

  //get entity from db by id
  EntityName dbEntity = session.get(EntityName.class, item.getProductId());

   //set property
  dbEntity.setStatus(entity.getStatus());

  //and update
  session.update(dbEntity);

}
0
source

Source: https://habr.com/ru/post/1795011/


All Articles