[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-3158) PersistentList.getDeletes issue when used with @OneToMany and @IndexColumn
Gail Badner (JIRA)
noreply at atlassian.com
Tue Mar 4 15:55:33 EST 2008
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3158?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gail Badner closed HHH-3158.
----------------------------
Assignee: Gail Badner
> PersistentList.getDeletes issue when used with @OneToMany and @IndexColumn
> --------------------------------------------------------------------------
>
> Key: HHH-3158
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3158
> Project: Hibernate3
> Issue Type: Bug
> Affects Versions: 3.2.2
> Reporter: Hao Chen
> Assignee: Gail Badner
>
> I have the following scenario:
> class Parent {
>
> @OneToMany(cascade={CascadeType.ALL})
> @IndexColumn(name="position", base=1)
> private List<Children> children;
> }
> And I am getting MySQL constraint error: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '332' for key 2
> The reason for the exception is that Hibernate generated association table has:
> table parent_children:
> parent_id
> children_id unique --- this causes duplicate key error
> position
> I have tracked this down, and it looks like PersistentList.getDeletes is not returning the correct index to be deleted:
> suppose: oldChildren siize is 3 and the association table is:
> parent_id=1, children_id=1, position=1;
> parent_id=1, children_id=2, position=2;
> parent_id=1, children_id=3, position=3;
> now I delete the first child: because getDeletes only use size to decide which one in the list to be deleted, it will return {2} because it assumes the last item is deleted.
> so, the 3rd child is deleted from the association table. There is still two rows in the association table:
> parent_id=1, children_id=1, position=1;
> parent_id=1, children_id=2, position=2;
> now, because child 2 is at position 1 now, Hibernate try to update position=1 to: parent_id=1, children_id=2, but children_id already exists at row 2. Thus the MySQLIntegrityConstraintViolationException is throw.
> I think the PersistentList.getDeletes should do the same thing as PersistentBag.getDeletes, which compare each element in the list to the snapshot list to decide which elements to delete.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list