I'm processing a batch of objects of which some are duplicates, say I'm processing a flatfile defining Students and some are the same (same natural key). The batch fails whenever a Student is added for the second time:
Code:
def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
basically my code:
Code:
Session session = getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
...
session.saveOrUpdate(student);
...
if (++recordCount % batchSize == 0) {
session.flush();
session.clear();
}
...
So I guess the problem is that before the flush, hibernate is unaware a student is a duplicate and hence prepares an insert-statement. How do I make hibernate aware of the student-name being the natural key?