JPA @ForeignKey not consistently applied from annotation binding

Description

This is a long standing issue. It is supposedly addressed by for 6.0 on the metamodel branch, but we need this fixed for 5.0, and in fact depending on the complexity we should really port this to 4.x...

This affects any of the values specified on JPA's ForeignKey annotation.

Activity

Show:

Mattias Öhrn October 11, 2016 at 6:26 PM

This bug is still in effect in 5.2 for JoinColumn. And @org.hibernate.annotations.ForeignKey no longer has any effect.

Christian Beikov June 6, 2016 at 9:06 AM

From a quick look for references I identified some other places where the @ForeignKey is not respected.

  • AssociationOverride.foreignKey()

  • JoinColumns.foreignKey()

  • MapKeyJoinColumns.foreignKey()

  • PrimaryKeyJoinColumns.foreignKey()

  • PrimaryKeyJoinColumn.foreignKey()

I am personally affected by JoinColumns missing support for the foreignKey, but the deprecated hibernate @ForeignKey annotation can at least be used as a workaround for now.
The JoinColumns case could be fixed by handling the JoinColumns annotation in AnnotationBinder.
So this is still an issue at least for hibernate 5.0.x. I can't tell for hibernate 5.1+ but as far as I can see in the code, it should still be problematic.

Please reopen @steve

Philippe February 29, 2016 at 4:40 PM

I precise that it doesn't work with the JPA @ForeignKey, you have to use hibernate's one

Philippe February 29, 2016 at 4:39 PM

Hy, I found a temporary solution for this issue in 4th version :

@org.hibernate.annotations.ForeignKey(name = "none")

But the problem is, will this annotation still be in hibernate in the next version (5) ?

Michael Rinne May 19, 2015 at 5:03 PM

Could you please create an issue for fixing this in version 4.x so that people can vote on it.
I would create an issue myself, but I am new here and I do not want to mess up your issue linking.
Furthermore, I would like to use this for schema export generating DDL scripts which create foreign key constraints with proper names.

Thanks,
Michael

Fixed

Details

Assignee

Reporter

Components

Fix versions

Priority

Created April 2, 2015 at 6:35 PM
Updated October 18, 2016 at 7:53 AM
Resolved April 2, 2015 at 10:04 PM