Hibernate deletion issue
Posted
by muffytyrone
on Stack Overflow
See other posts from Stack Overflow
or by muffytyrone
Published on 2010-05-07T03:59:42Z
Indexed on
2010/05/07
4:08 UTC
Read the original article
Hit count: 235
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.
© Stack Overflow or respective owner