[
http://opensource.atlassian.com/projects/hibernate/browse/HBX-1131?page=c...
]
Eric Sirianni commented on HBX-1131:
------------------------------------
Max - thanks for your quick comment.
My guess is that the MS Access JDBC driver has the same issue (returns null for FK_NAME).
My error actually came from using the sybase jConnect JDBC driver. Because it doesn't
return unique names for FK_NAME, I created my own metadata dialect that returned null for
the FK_NAME, hoping that the hibernate code would then handle this appropriately.
Instead, I hit this issue.
Any table whose primary key is a referent from multiple foreign keys should be enough to
make it fail.
The schema I'm working with is large and proprietary so I'll have to make a toy
example.
Table A {
Integer id (PRIMARY KEY)
String foo
}
Table B {
Integer a (FOREIGN KEY REFERENCES A.id)
String bar
}
Table C {
Integer a (FOREIGN KEY REFERENCES A.id)
String baz
}
When hibernate is calculating the referents of A's primary key, it asks the JDBC
driver for the foreign keys and gets back B (with FK_NAME null) and C (with FK_NAME null).
Hibernate assigns the FK_NAME "0" to both foreign keys, which leads to the
observed failure. You should be able to simulate this with the above schema and a bogus
MetadataDialect.
JDBCReader incorrectly generates bogus FK names
-----------------------------------------------
Key: HBX-1131
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-1131
Project: Hibernate Tools
Issue Type: Bug
Affects Versions: 3.2.4.GA
Environment: Tools 3.2.4 GA
Reporter: Eric Sirianni
Please see my forum post@
https://forum.hibernate.org/viewtopic.php?f=6&t=996016&p=2416464#...
JDBC drivers are allowed to return NULL for the "FK_NAME" metadata field for
foreign keys.
In this case, hibernate tries to generate a bogus FK name. This FK name must be unique
for the Table otherwise an exception is thrown:
org.hibernate.cfg.JDBCBinderException: Foreign key name (0) mapped to different
tables!
Hibernate's algorithm for generating the bogus FK name appears to be wrong. It
should increment the bogus FK name for each FK it finds, irrelevant of the
"KEY_SEQ" value.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira