Should Hibernate be able to handle overlapping foreign keys?

后端 未结 4 2053
难免孤独
难免孤独 2020-12-05 09:08

I have a table that has two foreign keys to two different tables with both foreign keys sharing one column:

CREATE TABLE ZipAreas
(
  countr         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 09:15

    This is still not solved in Hibernate 5. However, if I use @JoinColumnsOrFormulas I get ClassCastException. Appending insertable = false, updatable = false on all join columns solved my problem:

    Example:

    @ManyToOne
    @JoinColumns(value = {
        @JoinColumn(name = "country_code", referencedColumnName = "country_code", insertable = false, updatable = false),
        @JoinColumn(name = "state_code", referencedColumnName = "state_code", insertable = false, updatable = false), 
        @JoinColumn(name = "city_name", referencedColumnName = "name", insertable = false, updatable = false)})
    private City city = null;
    

提交回复
热议问题