[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (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 04:40:47 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5694?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38881#action_38881 ] 

Pascal Thivent edited comment on HHH-5694 at 10/27/10 3:39 AM:
---------------------------------------------------------------

By the way, here is the generated DDL for the join table:

create table foo_bar_map (
  foo_id bigint not null,
  bar_id bigint not null,
  order_index integer not null,
  primary key (foo_id, order_index),
  unique (bar_id)
)
alter table foo_bar_map add constraint FK14F1CB7FA042E82 foreign key (bar_id) references Bar
alter table foo_bar_map add constraint FK14F1CB7B6DBCCDC foreign key (foo_id) references Foo


      was (Author: pthivent):
    By the way, here is the DDL for the join table:

create table foo_bar_map (
  foo_id bigint not null,
  bar_id bigint not null,
  order_index integer not null,
  primary key (foo_id, order_index),
  unique (bar_id)
)

  
> 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