The problem is when I delete some entry from the m:n association and (saveOr)Update() the object tree Oracle throws "primary key unique constraint violation". It seems Hibernate is rearanging the association table to keep the List indexes in order and tries to update rows without having in mind the key association key is composite.
Hibernate version:2.1.3
Mapping documents:
noninverse List (Profile class):
Code:
<list name="queries" lazy="false" table="TPROFILE_TQUERY" cascade="none" >
<meta attribute="scope-set">private</meta>
<key>
<column name="FPROFILEID" sql-type="NUMBER(10)" length="10" />
</key>
<index column="FQUERYORDER"/>
<many-to-many class="net.buildercom.retriever.hibernate.Query" >
<column name="FQUERYID" sql-type="NUMBER(10)" length="10" />
</many-to-many>
</list>
inverse List (Query class):
Code:
<list name="profiles" lazy="true" table="TPROFILE_TQUERY"
cascade="none" inverse="true" >
<meta attribute="scope-get">private</meta>
<meta attribute="scope-set">private</meta>
<key>
<column name="FQUERYID" sql-type="NUMBER(10)" length="10"/>
</key>
<index>
<column name="FQUERYORDER" />
</index>
<many-to-many class="net.buildercom.retriever.hibernate.Profile" >
<column name="FPROFILEID" sql-type="NUMBER(10)" length="10" />
</many-to-many>
</list>
(Btw. no cascades are intentional)
Code between sessionFactory.openSession() and session.close():Code:
Query is removed from List Profile.queries based on id
Profile is updated()
Name and version of the database you are using:Oracle 9i
The generated SQL (show_sql=true):Association table generated by Hibernate:
Code:
create table TPROFILE_TQUERY (
FPROFILEID NUMBER(10) not null,
FQUERYID NUMBER(10) not null,
FQUERYORDER NUMBER(10,0) not null,
primary key (FQUERYID, FPROFILEID)
);
Code:
13:01:59,725 DEBUG SQL:237 - delete from TPROFILE_TQUERY where FPROFILEID=? and FQUERYORDER=?
13:01:59,819 DEBUG SQL:237 - update TPROFILE_TQUERY set FQUERYID=? where FPROFILEID=? and FQUERYORDER=?
13:01:59,897 WARN JDBCExceptionReporter:38 - SQL Error: 1, SQLState: 23000
13:01:59,897 ERROR JDBCExceptionReporter:46 - ORA-00001: unique constraint (RA.SYS_C005636) violated
Do you any suggestions how to solve it?
I have following ideas:
1) Instead of List use unindexed Collection (bad)
2) Create mapping for the association table (would this help at all?)
3) (2) + add artificial noncomposite key to the association table
Is there any other workaround (preferably with minimum changes) or am I doing something wrong?
Thanks
AJR