Hibernate deletion issue
- by muffytyrone
I'm trying to write a Java app that imports a data file. The process is as follows
Create Transaction
Delete all rows from datatable
Load data file into datatable
Commit OR Rollback if any errors were encountered.
The data loaded in step 3 is mostly the same as the data deleted in step3.
The deletion is performed using the following
DetachedCriteria criteria = DetachedCriteria.forClass(myObject.class);
List<myObject> myObjects = hibernateTemplate.findByCriteria(criteria);
hibernateTemplate.deleteAll(myObjects);
When I then load the datafile, i get the following exception
nested exception is org.hibernate.NonUniqueObjectException:
a different object with the same identifier value was already associated with the session:
The whole process needs to take place in transaction.
And I don't really want to have to compare the import file / data table and then perform an insert/update/delete to get them into sync.
Any help would be appreciated.