[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-5694) Unique constraint violation when removing an item from a unidirectional OneToMany ordered List
Pascal Thivent (JIRA)
noreply at atlassian.com
Wed Oct 27 01:34:50 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5694?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pascal Thivent updated HHH-5694:
--------------------------------
Attachment: HHH-5694.zip
Replaces previous attachment.
> Unique constraint violation when removing an item from a unidirectional OneToMany ordered List
> ----------------------------------------------------------------------------------------------
>
> Key: HHH-5694
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5694
> Project: Hibernate Core
> Issue Type: Bug
> Components: entity-manager
> Affects Versions: 3.5.0-Final, 3.5.1, 3.5.2, 3.5.3, 3.5.4, 3.5.5, 3.5.6, 3.6.0
> Environment: Tested with Hibernate 3.5+ on H2, Derby, HSQLDB
> Reporter: Pascal Thivent
> Attachments: HHH-5694.zip, HHH-5694.zip
>
>
> I have a {{Foo}} entity that has a unidirectional ordered {{OneToMany}} {{List}} of {{Bars}}:
> {code}
> @Entity
> public class Foo {
> @Id @GeneratedValue
> private Long id;
> @OneToMany
> @OrderColumn(name = "order_index")
> @JoinTable(name = "foo_bar_map", joinColumns = @JoinColumn(name = "foo_id"), inverseJoinColumns = @JoinColumn(name = "bar_id"))
> private List<Bar> bars;
> //...
> }
> {code}
> So let's say {{Foo#1}} holds a list with {{Bar#1}}, {{Bar#2}}, {{Bar#3}} (in that order). When removing {{Bar#1}} from the List and persisting [[Foo#1}}, Hibernate performs the following weird SQL:
> {code}
> delete from foo_bar_map where foo_id=1 and order_index=2
> update foo_bar_map set bar_id=2 where foo_id=1 and order_index=0
> {code}
> And this obviously fails with a unique constraint violation. Why does Hibernate delete the last item from the join table? Why does Hibernate mess with the bar_id? Shouldn't Hibernate update the order_column instead?
> I'm attaching a mavenized test allowing to reproduce, run {{mvn test}}.
> FWIW, this works with the RI (run {{mvn test -Peclipselink,h2}}).
--
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