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.
Hibernate 3.6.0, HSQLDB 2, JavaSE (probably all Hibernate versions to date affected)
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?
It's been lingering here for years now. I don't think it'll ever be corrected.
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...
The work around mentioned in the SO can lead to the issue.