Hi,
I have an entity "Foo" that has a uni-directional many-to-many relationship to another entity "Bar":
Code:
@ManyToMany ( fetch = FetchType.LAZY )
@IndexColumn ( name = "c_index")
@JoinTable ( name = "t_FooBar",
joinColumns = @JoinColumn ( name = "c_FooUid" ),
inverseJoinColumns = @JoinColumn ( name = "c_BarUid" ) )
private List<Bar> bars;
When I execute the following code:
Code:
//update the position of 'bar' within the list
foo.bars.remove(bar);
foo.bars.add( newIndex, bar);
Hibernate issues the following SQL statement:
Code:
/* update collection row Foo.bars */
update
t_FooBar
set
c_BarUid=?
where
c_FooUid=?
and c_index=?
This, however, causes a constraint violation, since the primary key is (c_FooUid, c_BarUid).
The statement I'd expect is:
Code:
update
t_FooBar
set
c_index=?
where
c_FooUid=?
and c_BarUid=?
i.e. update the index of (foo,bar) instead of setting a new bar for (foo,index).
Any ideas of how I could change that? Am I missing something?
Thanks in advance.
Regards,
Thomas