Reputation: 117
As is known, Hibernate uses dirty check - that is, in DB it changes only fields that have changed in the entity of the program. How to know which fields have changed? Can I get old values?
Upvotes: 0
Views: 888
Reputation: 21113
There are a series of event listener SPIs in org.hibernate.event.spi
that you can implement and register during the construction of a SessionFactory
where you can obtain the state information your asking about. For example:
public class MyPreUpdateEventListener implements PreUpdateEventListener {
@Override
public boolean onPreUpdate(PreUpdateEvent event) {
Object[] newState = event.getState();
Object[] oldState = event.getOldState();
/* from this point, you'd need to determine the differences yourself */
}
}
Upvotes: 1