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

后端 未结 4 1255
小鲜肉
小鲜肉 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:36

    No I don't think it's a hibernate bug, and as you will see if you do searches this hibernate bug quoted by Pascal Thivent is a bug known since 2006 and has never been solved.

    Why ?

    Cause I think the problem is just in the constraints on the table and not in hibernate.

    I don't understand why there is a unique constraint on bar_id

    Using an order index means your collection is a List (and not a Set !). And a List is a collection where you can specify index to elements you add (it corresponds to OrderColumn).
    The difference between a List and a Set is that you and can the same data twice (or more), but the same data will be at different indexes. Then you can have the same bar_id a different indexes, you don't have to specify a unique constraint on bar_id. And the primary key can't be (foo_id, order_index) cause the pattern List authorize the same data at different indexes. Maybe your PK should be (foo_id, bar_id, order_index) ?

    I think the problem is in this way :)

提交回复
热议问题