-->
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.  [ 3 posts ] 
Author Message
 Post subject: Error reorder many to many map list
PostPosted: Fri Oct 27, 2006 2:50 pm 
Newbie

Joined: Fri Oct 27, 2006 2:28 pm
Posts: 14
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.


Top
 Profile  
 
 Post subject: Update - Error when save reordered many to many list
PostPosted: Mon Oct 30, 2006 11:54 am 
Newbie

Joined: Fri Oct 27, 2006 2:28 pm
Posts: 14
Here's an update on the generated SQL and hibernate log:

2006-10-30 10:13:41,084 DEBUG [http-8080-Processor20] (UpdateTimestampsCache.java:51) - Pre-invalidating space [AAAA.USER_DOCUMENTS]

2006-10-30 10:13:41,084 DEBUG [http-8080-Processor20] (AbstractCollectionPersister.java:1079) - Deleting rows of collection: [User.documents#676124]

2006-10-30 10:13:41,194 DEBUG [http-8080-Processor20] (AbstractCollectionPersister.java:1136) - no rows to delete


2006-10-30 10:13:41,194 DEBUG [http-8080-Processor20] (AbstractCollectionPersister.java:1333) - Updating rows of collection: User.documents#676124

2006-10-30 10:13:41,194 DEBUG [http-8080-Processor20] (AbstractBatcher.java:311) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)

2006-10-30 10:13:41,194 DEBUG [http-8080-Processor20] (AbstractBatcher.java:346) - update AAAA.USER_DOCUMENTS set userId=? where documentId=? and documentIndex=?


With this new information, could someone please give me some hints on how to address this problem? I start to suspect this is hibernate problem. However, it's shocking to think that a well known OR mapping such as hibernate cannot work well with an ordered list.

I remove the primary key constraint of USER_DOCUMENTS table (the userId and documentId) and things work. However, this is a workaround and not a fix. I also notice that there is no extra row in this table after I reorder items. So, the duplicate entry error is obviously something wrong DURING the updating process of the list.

Thanks,

hovh03


Top
 Profile  
 
 Post subject: Update 2 - Error when save reordered many to many list
PostPosted: Mon Oct 30, 2006 1:42 pm 
Newbie

Joined: Fri Oct 27, 2006 2:28 pm
Posts: 14
I download and use the latest GA version 3.2, and the problem is still there. Below is the stack trace:



2006-10-30 12:38:06,490 INFO [http-8080-Processor21] (JdbcTransactionObjectSupport.java:60) - JDBC 3.0 Savepoint class is available
2006-10-30 12:38:06,631 WARN [http-8080-Processor21] (JDBCExceptionReporter.java:71) - SQL Error: 1, SQLState: 23000
2006-10-30 12:38:06,631 ERROR [http-8080-Processor21] (JDBCExceptionReporter.java:72) - ORA-00001: unique constraint (AAAA.USER_DOCUMENTS_PK) violated

2006-10-30 12:38:06,631 WARN [http-8080-Processor21] (JDBCExceptionReporter.java:71) - SQL Error: 1, SQLState: 23000
2006-10-30 12:38:06,631 ERROR [http-8080-Processor21] (JDBCExceptionReporter.java:72) - ORA-00001: unique constraint (AAAA.USER_DOCUMENTS_PK) violated

2006-10-30 12:38:06,647 ERROR [http-8080-Processor21] (AbstractFlushingEventListener.java:301) - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)


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

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.