Hi all,
I have a case when N threads can modify the same entity concurrently. The problem I've faced with is that entity is fully overwritten by each thread.
E.g. if 1st thread tries to modify username and 2nd - password, I expect to see both username and password updates. But last thread overwrites entire entity. Of course if 2 threads try to modify the same column, only latest changes should be applied. But in case of different modifications it would be nice to see merge effect.
So my question is: how to handle such situations and prevent entire entity overwriting?
Here's saving API:
Code:
public void save(final T entity) {
try {
createNewSessionAndTransaction();
if (session != null && entity != null) {
session.saveOrUpdate(entity);
}
commitTransaction();
} catch (HibernateException e) {
rollbackTransaction();
}
}
Hibernate config contains:
Code:
<property name="current_session_context_class">thread</property>
Thanks,
Sergey