I use a list. The list is comprised of a compound primary key which is also used for sorting the list.
The problem is that if I delete an element in the list (key compound),
annotation @OrderColumn
generates a request to update a primary key, and the cost rises an exception of type:
[26-05-2011 10:34:18:835] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1062, SQLState: 23000
[26-05-2011 10:34:18:835] ERROR org.hibernate.util.JDBCExceptionReporter -Duplicate entry '10-10' for key 'PRIMARY'
[26-05-2011 10:34:18:835] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
Here is the definition of the mapping :
@ManyToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "chapter_item", joinColumns = { @JoinColumn(name = "chapter_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "item_id", nullable = false, updatable = false) })
@OrderColumn(name="iorder")
public List<Item> getItems() {
return items;
}
Here is the update query where I have a problem:
Hibernate:
update
chapter_item
set
item_id=?
where
chapter_id=?
and iorder=?
I wonder if this is a known bug, and if anyone has a solution?