Constraint violation in Hibernate unidirectional OneToMany mapping with JoinTable and OrderColumn when removing elements

后端 未结 4 1251
小鲜肉
小鲜肉 2020-12-28 17:26

I have a problem when removing elements from a list mapped as described above. Here is the mapping:

@Entity
@Table( name = \"foo\")
class Foo {

    private List          


        
4条回答
  •  庸人自扰
    2020-12-28 17:31

    Usually when joining through a join table the relationship is ManyToMany not OneToMany. Try this

    @ManyToMany
    @OrderColumn( name = "order_index" )
    @JoinTable( name = "foo_bar_map", joinColumns = @JoinColumn( name = "foo_id" ), inverseJoinColumns =  @JoinColumn( name = "bar_id" ) )
    @Fetch( FetchMode.SUBSELECT )
    public List getBars() {
        return bars;
    }
    

提交回复
热议问题