-->
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.  [ 4 posts ] 
Author Message
 Post subject: exception when changing order of an indexed collection
PostPosted: Wed Feb 15, 2006 5:20 am 
Newbie

Joined: Wed Feb 15, 2006 4:47 am
Posts: 2
Hibernate version: 3.1.1
Database: Mysql 4.1.12a-nt

I have mapped a property to an indexed collection as follows:
Code:
@OneToMany()
@Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN})
@IndexColumn(name="position")
public List<Section> getSections() {
   return sections;
}

The indexed collection contains some entities and I want to change the position of an entity by doing the following steps within a transaction:
Code:
Section section = session.get(Section.class, sectionId);
sections.remove(section);
sections.add(newIndex, section)

when committing the following exception is thrown:
Code:
java.sql.BatchUpdateException: Duplicate entry '3' for key 2

Do I use a wrong method to change the position of an entity in an indexed collection?
What would be the correct way to change positions?
Or is it even impossible to do it in only one transaction?


Top
 Profile  
 
 Post subject: remove
PostPosted: Thu Feb 16, 2006 7:50 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Perhaps remove method does not delete element from collection. There might be vwrious reasons for that, but the net result is that there are two "identical" elements in the collection.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 3:47 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

Post your mappings. How is the collection managed ? Provide some additional details (but no more than 15-20 lines).


Top
 Profile  
 
 Post subject: Mapping
PostPosted: Fri Feb 17, 2006 4:06 am 
Newbie

Joined: Wed Feb 15, 2006 4:47 am
Posts: 2
TOMBATLECRUISEr wrote:
Hi,

Post your mappings. How is the collection managed ? Provide some additional details (but no more than 15-20 lines).

I have given the mapping already. It is done with Hibernate Annotations 3.1beta7.
iterator wrote:
@OneToMany()
@Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN})
@IndexColumn(name="position")
public List<Section> getSections() {
return sections;
}

This means I have a OneToMany mapping to a collection of Section entities with an index column named position and a cascade ALL that includes even DELETE_ORPHAN.
I don't think that the mapping is the problem but there must be a normal way to do a position change.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.