Hibernate version:3.1.3
Database: Oracle
Hi,
I have a basic question. I shows all relevant stuff below (which seems long), but summary is all it is below:
I have an ordered list map using many to many. The problem is that I can add an item to the list. I can delete an item from the list. However, I cannot order the item. The error is:
unique constraint (AAAA.User_Documents_PK) violated
Here's my classes:
Code:
Class User {
Long id;
List documents;
}
Class Document {
Long id;
String data;
}
A user does not own documents. It only references some documents. So this is many to many mapping.
I have table "User", "Document" and "User_Documents"
User_Documents table has:
userId
documentId
documentIndex
These are foreign keys to the user.id and document.id table. Both of them also form a primary key.
The mapping for User class looks like this:
Code:
<class name="User" table="User" >
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
...
</generator>
</id>
<list name="documents" table="User_Documents">
<key column="userId"/>
<list-index column="documentIndex" base="0"/>
<many-to-many column="documentId" class="Document"/>
</list>
</class>
An error occurs if I have two items in the user.documents list swapped, and I save the user object.
Could someone please help. Thank you in advance.