Mapping a bidirectional list with Hibernate

前端 未结 1 1643
我寻月下人不归
我寻月下人不归 2021-02-06 09:09

I don\'t understand the behavior of Hibernate when mapping a bidirectional list. The SQL statements that Hibernate produces seem not optimal to me. Can somebody enlighten me?

1条回答
  •  抹茶落季
    2021-02-06 09:45

    Ok, I was not reading the Annotations Reference Guide thoroughly enough.

    In Chapter 2.2.5.3.1.1. Bidirectional it is stated clearly:

    To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and set the many to one @JoinColumn as insertable and updatable to false. This solution is obviously not optimized and will produce some additional UPDATE statements.

    It probably would not hurt to repeat this information in Chapter 2.4.6.2.1. Bidirectional association with indexed collections .

    Now the question remains: if I repeat the @JoinColumn attributes 'updatable = false' and 'insertable = false' on the Parent (see code in first post) the additional update statements seem not to get produced... is this a legitimate workaround? Or does this result in another problem?

    0 讨论(0)
提交回复
热议问题