-->
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: Unidirection OneToMany, IndexColumn duplicate entry error
PostPosted: Tue Nov 24, 2009 11:35 am 
Newbie

Joined: Tue Nov 24, 2009 11:19 am
Posts: 2
Hi,

I am using Hibernate 3.3.2 with Annotations 3.4.0 and MySql 5.1.

With the following mapping:
Code:
   
    @OneToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "user_profile_photo",
    joinColumns = {@JoinColumn(name = "user_profile_id")},
    inverseJoinColumns = {@JoinColumn(name = "photo_id")})
    @IndexColumn(name = "ordinal")
    public List<Photo> getPhotos() {
        return photos;
    }


So what I'm trying to do is move the order of the photos around. The exact case is that the ids of my photos list are: <12>, <13>, <14> and when I switch them around and try to commit <14>, <13>, <12>, I am getting the following error:

Code:
2009-11-24 10:06:18,608 DEBUG org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:92)  - Could not execute JDBC batch update [update user_profile_photo set photo_id=? where user_profile_id=? and ordinal=?]
java.sql.BatchUpdateException: Duplicate entry '12' for key 'photo_id'
   at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2007)
...


Am I doing something wrong with the mapping? Do I need to destroy the list in order to update the order of them (that seems wrong)?

Potentially useful log fragment from just before the error:
Code:
2009-11-24 10:06:18,588 DEBUG org.hibernate.cache.UpdateTimestampsCache.preinvalidate(UpdateTimestampsCache.java:66)  - Pre-invalidating space [user_profile_photo]
2009-11-24 10:06:18,588 DEBUG org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:1226)  - Deleting rows of collection: [com.hv.tfm.users.UserProfile.photos#9]
2009-11-24 10:06:18,592 DEBUG org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:1309)  - no rows to delete
2009-11-24 10:06:18,592 DEBUG org.hibernate.persister.collection.AbstractCollectionPersister.updateRows(AbstractCollectionPersister.java:1537)  - Updating rows of collection: com.hv.tfm.users.UserProfile.photos#9
2009-11-24 10:06:18,593 DEBUG org.hibernate.jdbc.util.SQLStatementLogger.logStatement(SQLStatementLogger.java:111)  -
    update
        user_profile_photo
    set
        photo_id=?
    where
        user_profile_id=?
        and ordinal=?
2009-11-24 10:06:18,593 DEBUG org.hibernate.persister.collection.AbstractCollectionPersister.updateRows(AbstractCollectionPersister.java:1544)  - done updating rows: 2 updated
2009-11-24 10:06:18,594 DEBUG org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1335)  - Inserting rows of collection: [com.hv.tfm.users.UserProfile.photos#9]
2009-11-24 10:06:18,594 DEBUG org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1412)  - done inserting rows: 0 inserted


Top
 Profile  
 
 Post subject: Re: Unidirection OneToMany, IndexColumn duplicate entry error
PostPosted: Mon Nov 30, 2009 10:34 am 
Newbie

Joined: Tue Nov 24, 2009 11:19 am
Posts: 2
does anyone have any clue? Any help would be appreciated.


Top
 Profile  
 
 Post subject: Re: Unidirection OneToMany, IndexColumn duplicate entry error
PostPosted: Mon Dec 19, 2011 6:23 am 
Newbie

Joined: Wed Apr 18, 2007 7:22 am
Posts: 4
This is a bug. For a workaround, see: https://hibernate.onjira.com/browse/HHH-3160


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.