1

How to get which properties were updated after hibernate update? For example if I got

SomeEntity se = new SomeEntity();
getHibernateTemplate().save(se); 

//then in some other method
se.setProp1("some new value");

//then in 3th method
getHibernateTemplate().update(se);

If you tell hibernate to do dynamic update it will know witch properties were changed and update only them. Is there a way to get the ones that were changed or to check is specific property was changed?

Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145
  • Don't know if useful but have a look at this [old stackoverflow topic](http://stackoverflow.com/questions/14125558/hibernate-envers-get-fields-that-have-changed) – Paolo Nov 08 '13 at 16:45
  • Try also [here](http://stackoverflow.com/questions/2521575/is-there-a-way-to-get-only-the-changed-columns-from-an-object-using-hibernate) and [here](http://stackoverflow.com/questions/8354642/need-to-know-if-each-field-has-changed-how-should-i-model-this-in-hibernate) – Paolo Nov 08 '13 at 16:49

1 Answers1

0

Ended up doing native sql query to compare the state in the db with the state in the entity before flush the session.

Query query = session.createSQLQuery(
"select t.someProp1 from someTable t where t.id = :entityId")
.setParameter("entityId", entity.getId());
List result = query.list();
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145