NamingStrategy should support naming foreign keys and indexes
-------------------------------------------------------------
Key: HHH-3499
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3499
Project: Hibernate Core
Issue Type: Improvement
Components: metamodel
Affects Versions: 3.3.1
Reporter: Geoffrey De Smet
hbm2ddl always generates foreign key constraints based on hashcodes, like this:
alter table apple add index FK365FA4BB24B1D45C (lemon_id), add constraint
FK365FA4BB24B1D45C foreign key (lemon_id) references lemon (id);
Some databases don't support enough characters for foreign key names to generate a
readable foreign key name, so that's a sensible default.
However, those of use that use databases like MySQL etc, would like a readable foreign key
name, such as:
alter table apple add index FK_Apple_lemon (lemon_id), add constraint FK365FA4BB24B1D45C
foreign key (lemon_id) references lemon (id);
We can do that by annotating every entity with @Index in JPA, or specifying it in a hbm
file,
but we can't do it generally, by extending DefaultNamingStrategy or
ImprovedNamingStrategy.
Here's a proposition on how we could do it:
- In the NamingStrategy interface, next to the method foreignKeyColumnName, add a method:
public String foreignKeyConstraintName(String propertyName, String propertyEntityName,
String propertyTableName, String referencedColumnName
- DefaultNamingStrategy and ImprovedNamingStrategy should implement it as it is now, based
on hashcodes.
- If a mapping has an @Index JPA annotation or it's specified in a hbm file, that
override counts.
--
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