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