I just noticed that Hibernate objects are automatically stored in the database (or at least in the cache) before I call any methods save()or update(). For me, this is a rather weird default behavior - but it's fine, if I can disable it, that's fine.
The problem is that I want to update the state of my object (from state "1" to state "2") only if the entity in the database still has the state that it had when it was restored (state "1" "). This fixes concurrency problems when another server updates the same object. For this reason, I created a custom NamedQueryone that will only update the object if it is in the expected state" 1. "Here are a few pseudo codes:
Entity item = dao.getEntity();
item.getState();
item.setState(2);
dao.customUpdate(item);
How to make sure that setters do not change state in / db cache?
source
share