-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Composite key unique violation in many-to-many List
PostPosted: Sun Nov 07, 2004 8:34 pm 
Newbie

Joined: Wed Aug 25, 2004 10:54 am
Posts: 12
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.