I am adjusting a Java program which writes incoming data into a table in a Firebird database. The database connection is abstracted by Hibernate. The command used to save the data is saveOrUpdate(). Some of these incoming data are new and need to be inserted, other exist already and need to be updated.
This works fine so far.
The problem I have occurs when removing rows from the database, e.g. by another thread. The next time data come in which existed already before the deletion Hibernate still tries to update and throws the exception
Code:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
Is there a possibility to tell Hibernate the removal of entries so it does not try an update the next time but an insert?
The program does not open a new session each time but retrieves the current session when accessing the stored data:
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
// do sth with session
session.getTransaction().commit();