-->
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.  [ 2 posts ] 
Author Message
 Post subject: @OneToMany with @IndexColumn. Bug in deleting from the List
PostPosted: Thu Jun 08, 2006 4:28 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
There is a very bad bug with deleting from an ordered @OneToMany List.

I have the following:

Code:
   @OneToMany(fetch=FetchType.EAGER)
   @Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
   @IndexColumn(name="submenuIndex")
   public List<Menu> getSubMenus()
   {
      if (subMenus == null)
         subMenus = new ArrayList<Menu>();
      return subMenus;
   }
   public void setSubMenus(List<Menu> subMenus)
   {
      this.subMenus = subMenus;
   }


If I ever do

Code:
   myMenu.getSubmenus().remove(0);
   myEntityManager.flush();


I get

Code:
07:32:09,296 INFO  [fcl] Removing old menu entry 186: MenuOption:Application Classes (AppClass) from Menu:App. Data
07:32:09,296 INFO  [fcl] Updating Menu:App. Data with submenu changes...

07:32:09,296 INFO  [fcl] greenfield/admin is about to update Menu:App. Data
07:32:09,359 INFO  [fcl] greenfield/admin is about to update Menu:Static Data
07:32:11,062 INFO  [fcl] greenfield/admin is about to update MenuOption:Application Classes (AppClass)
07:32:11,062 INFO  [fcl] greenfield/admin is about to update MenuOption:Tax Number Validation Methods (AppTaxNoValidation)
07:32:11,062 INFO  [fcl] greenfield/admin is about to update MenuOption:Application Components (AppComponent)
07:32:11,062 INFO  [STDOUT] Hibernate: update Menu set parent_uuid=?, version=?, description=?, creatingUser=?, createdDateTime=?, modifiedDateTime=?, modifyingUser=?, houseComponent_uuid=? where uuid=? and version=?
07:32:11,078 INFO  [STDOUT] Hibernate: update Menu set parent_uuid=?, version=?, description=?, creatingUser=?, createdDateTime=?, modifiedDateTime=?, modifyingUser=?, houseComponent_uuid=? where uuid=? and version=?
07:32:11,078 INFO  [STDOUT] Hibernate: update Menu set parent_uuid=?, version=?, description=?, creatingUser=?, createdDateTime=?, modifiedDateTime=?, modifyingUser=?, houseComponent_uuid=? where uuid=? and version=?
07:32:11,078 INFO  [STDOUT] Hibernate: update Menu set parent_uuid=?, version=?, description=?, creatingUser=?, createdDateTime=?, modifiedDateTime=?, modifyingUser=?, houseComponent_uuid=? where uuid=? and version=?
07:32:11,078 INFO  [STDOUT] Hibernate: update Menu set parent_uuid=?, version=?, description=?, creatingUser=?, createdDateTime=?, modifiedDateTime=?, modifyingUser=?, houseComponent_uuid=? where uuid=? and version=?
07:32:11,078 INFO  [STDOUT] Hibernate: delete from Menu_subMenus where Menu_uuid=? and submenuIndex=?
07:32:11,093 INFO  [STDOUT] Hibernate: update Menu_subMenus set subMenus_uuid=? where Menu_uuid=? and submenuIndex=?
07:32:11,093 WARN  [JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
07:32:11,687 ERROR [JDBCExceptionReporter] Duplicate key or integrity constraint violation message from server: "Duplicate entry '209' for key 1"


From the mysql log:

Code:
                      3 Query       delete from Menu_subMenus where Menu_uuid=74 and submenuIndex=2
                      3 Query       update Menu_subMenus set subMenus_uuid=209 where Menu_uuid=74 and submenuIndex=0
                      3 Query       update Menu_subMenus set subMenus_uuid=188 where Menu_uuid=74 and submenuIndex=1


So what it's doing when List elements are removed, is just deleting excess from the end of the link table - in this case, removing element 2. That's OK.

And then going down the remaining link rows (0 and 1), changing them to point to the new values.

Unfortunately, it (Hibernate) created the link table with a "Unique" constraint on the child key, so the set of "subMenus_uuid" to 209 fails at submenuIndex=0 because this already exists at submenuIndex=1.

It's a BUG and it's a showstopper.


Last edited by Animal on Wed Jul 05, 2006 9:05 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 8:24 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
So, I've seen quite a few people hitting this: http://forum.hibernate.org/viewtopic.php?t=960682

Probably more people have hit this, but I just checked thread titles.

There's a JIRA http://opensource.atlassian.com/project ... e/HHH-1296

This needs to be fixed. List collections with an IndexColumn do not work because of the way it updates. It duplicates keys as it passes down the list updating the join table. It only does this transiently, but the database doesn't like it.

Either make the updating algorithm cleverer, or do not add the Unique constraint to the keys when creating the join table!


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