Hibernate version: 3.1.1
Database: Mysql 4.1.12a-nt
I have mapped a property to an indexed collection as follows:
Code:
@OneToMany()
@Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN})
@IndexColumn(name="position")
public List<Section> getSections() {
return sections;
}
The indexed collection contains some entities and I want to change the position of an entity by doing the following steps within a transaction:
Code:
Section section = session.get(Section.class, sectionId);
sections.remove(section);
sections.add(newIndex, section)
when committing the following exception is thrown:
Code:
java.sql.BatchUpdateException: Duplicate entry '3' for key 2
Do I use a wrong method to change the position of an entity in an indexed collection?
What would be the correct way to change positions?
Or is it even impossible to do it in only one transaction?