//commit and close session1
session2.flush(); //should fail on uniqueConstrains ...
Repository rpy = new Repository(key);
session2.flush(); //should NOT fail on uniqueConstrains (row already in the database)...
//commit and close session2
session2 invoke saveOrUpdate(object) before session1 commit and close it transaction.
so actually session2, make a select to see if it should insert, or update it's data.
In that case since session1 still not committed, session2 will make insert after it make flush() and get org.hibernate.exception.ConstraintViolationExcepti on.
Till now, everything is ok ... I want to check that in some test in our system.
But, after I commit with session1 and make the same operation with session2 (i.e saveOrUpdate(obj) and then flush()) I am expecting to get update operation on the object since it's already in the DB.
I am working with hibernate.
It works fine with Oracle DB, but not as expected with MySQL (i.e with Oracle I get only once ConstraintViolationException and it updating in the second time, but I am getting twice ConstraintViolationException when I am working infront of MySQL DB)
Do, someone, now the reason why and how can I solve it???
I tried to remove second-level-cache in hibernate configuration file, I tried to change the CacheMode of the session, unfortunately, nothing helped.