One to many association - Join tables with non primary key column in JPA

后端 未结 2 1088
旧时难觅i
旧时难觅i 2020-12-19 01:44

I\'m working on legacy system, need to read some of the info from database. Below are the table relationship

Vendor (vendorId - pk, vendorEid, name)
VendorCont

相关标签:
2条回答
  • 2020-12-19 02:18

    I found a workaround for this problem.

    See here:

    • https://stackoverflow.com/a/4525951/527718
    0 讨论(0)
  • 2020-12-19 02:21

    According to the JPA 2.0 specs paragraph 11.1.21 JoinColumn annotaion on page 379

    Support for referenced columns that are not primary key columns of the referenced table is optional. Applications that use such mappings will not be portable.

    It seems Hibernate choose not to implement this optional part. Other implementations might. I tried it on EclipseLink but that one does not work either (it fails validation).

    I see two work arounds. One is to adjust your schema to use the primary keys which would be the right thing from a database design theory perspective. However that might not be an option because of other software depending on this schema which leaves option two. Work around it by NOT moddeling the relationship in JPA just use the eid's and retrieve the relevant objects yourself.

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