[SchemaUpdate] javax.persistence.ForeignKey doesn't respect ConstraintMode.NO_CONSTRAINT

Description

@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))

hibernate will still try to add constraint

2013-12-18 11:25:37,036 localhost-startStop-1 org.hibernate.tool.hbm2ddl.SchemaUpdate ERROR HHH000388: Unsuccessful: alter table oauth_client add constraint FK_43dmxuh3574xhqwmvkt8gdwqf foreign key (owner) references `user` (id)

Environment

jpa2.1 hibernate4.3.0.Final mysql5.6 jdk7

Activity

Show:
Robert Rettig
July 9, 2018, 4:24 PM

Just asking if someone would reopen that case because of copy paste coding without thinking.

Code reading comprehension training:

  • what is secondaryTable2 good for?

  • why this fix is a new bug for a bug?

Who should we blame for the author or the hibernate code policies? Such code could be easily rejected by a simple rule. Now it is part of hibernate since Date: 4/3/15 12:02 AM.
From that point of view I really understand that no one is doing real legacy database integration work with hibernate, because it is a pain of debugging.

May be interessting for you, this comes from a real application which tries to use secondary tables with no foreignkey generation (it would disturb an legacy application which works on that database too). The many ForeignKey annotations express the desperate attempt to teach hibernate the correct behavior.

Christian Beikov
July 10, 2018, 8:38 AM

Thanks for the fix, I will look into getting this in. There is nobody to blame, bugs happen and get fixed at some point. I guess you don't write bug free software either? Remember, this is an open source project maintained by many individuals and everyone has their own main projects.

Robert Rettig
July 10, 2018, 8:50 AM

Thanks and I totally agree with your response.
I recognized that hibernate has sophisticated use of findbugs, becaues I needed to rebuild it for myself applying some patches (for playframework) and struggled with those findbugs and clean code rules. They really could find such neve used local variable definitions and reject/error the build process in that case. If you open the file with a modern ide like intellij (maybe eclipse too) it will point that out by default (at least by special color of that variable).

Vlad Mihalcea
July 10, 2018, 8:58 AM
Edited

Since I joined the team, we've been adding a replicating test case to every fix so this kind of silly mistakes are prevented.

Nevertheless, after analyzing it, I realized that I was unlikely that someone would add a specific test for @SecondaryTables as this cannot happen with just @SecodnaryTable.

So, it's unfair to put blame on the original committer. If it's code, it will have bugs. Most people don't realize that once they use a certain framework that becomes part of their stack. So, any problem in the framework becomes their problem as well. The whole purpose of OSS is to step in and provide fixes, test cases, etc. Blaming makes no sense either for commercial software or OSS.

周雁鸣
July 10, 2018, 10:28 AM

Eclipse will indicate this as "The value of the local variable secondaryTable2 is not used", Much appreciated if hibernate team could eliminate IDE warnings.

Assignee

Vlad Mihalcea

Reporter

周雁鸣

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure