I have a Foo entity that has a unidirectional ordered OneToMany List of Bars:
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:
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).
Tested with Hibernate 3.5+ on H2, Derby, HSQLDB
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),
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
Replaces previous attachment.
Bulk closing stale resolved issues