Unique constraint violation when removing an item from a unidirectional OneToMany ordered List

Description

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).

Environment

Tested with Hibernate 3.5+ on H2, Derby, HSQLDB

Activity

Show:
PascalP
October 27, 2010, 7:30 AM
Edited

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

PascalP
October 27, 2010, 7:34 AM

Replaces previous attachment.

Steve Ebersole
March 21, 2011, 7:08 PM

Bulk closing stale resolved issues

Assignee

Gail Badner

Reporter

PascalP

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure