jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
186 stars 55 forks source link

Allow @JoinColumns without an explicit @JoinColumn list #639

Open gavinking opened 2 weeks ago

gavinking commented 2 weeks ago

A semi-hidden function of the @JoinColumns annotation is to specify a @ForeignKey. Unfortunately, you're required to specify an explicit list of child @JoinColumns even when all you want to do is name the foreign key.

(All this also applies to @PrimaryKeyJoinColumns.)

Possible fixes:

  1. specify value default {}, with the interpretation that the @JoinColumns are defaulted , or
  2. allow @ForeignKey as a top-level annotation on association mappings (and joined inheritance mappings).

Option 2 minimizes verbosity. But at the cost of being a bit inconsistent with how @UniqueKey, @CheckConstraint, and @Index work.

PR https://github.com/jakartaee/persistence/pull/638 implements option 1, which has minimal impact.