Hibernate throws AnnotationException on column used by multiple overlapping foreign keys

Description

Here's a view of the design:

Simple logic: two tables use composite PKs and use a country_code column in the PK. PostAreas is a simple join table so its PK is comprised of the two linked tables' PK columns. Problem: both FKs in PostAreas use country_code to produce an overlap.

This is per se nothing special, but in the context of JPA it is: there may be only one writable mapping in the @JoinColumn annotations, all other must be set to read-only, that is insertable = false, updatable = false.

Here are the (incomplete) mappings (full SSCCE attached):

Looking at PostArea.city (scroll down in the PostArea code box!): the @JoinColumn for country_code is set to read-only on City and to writable on Zip. However, when running this from a JavaSE test app Hibernate fails with an AnnotationException:

When mapping a table that uses the same column in two or more foreign keys, only one of the relationships' @JoinColumn annotations may be tagged as writable. However, mixing read-only and writable in a multi-column relationship must be supported.

Environment

Hibernate 3.6.0, HSQLDB 2, JavaSE (probably all Hibernate versions to date affected)

Activity

Show:
Guillaume BILLEY
February 20, 2019, 8:25 AM

Hi! Any update for this issue?
I'm having the same usecase and trying to find a solution to this.
Is tehre any known workaround as it seems to not have been fixed yet?

Paweł Jaguś
February 20, 2019, 8:47 PM

It's been lingering here for years now. I don't think it'll ever be corrected.

Guillaume BILLEY
February 21, 2019, 10:04 AM

Unfortunately that was my guess... But I have found a workaround, using @JoinColumnsOrFormulas as stated in this SO : https://stackoverflow.com/questions/54783965/hibernate-composite-key-and-overlapping-field-how-to-avoid-column-duplication
If it can help someone...

IT Support
May 22, 2020, 1:58 PM
IT Support
May 22, 2020, 2:13 PM

The work around mentioned in the SO can lead to the issue.

Assignee

Unassigned

Reporter

Ka Wu

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure