[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3499?page=c...
]
Tim Twe commented on HHH-3499:
------------------------------
+1
This is important.
There certain database restrictions such as maximum table length introduce certain
corporate standards that utilize reserved words, etc. The ability to provide a custom
strategy will be invaluable.
@ForeignKey is sufficient but it is my understanding that this is hibernate only and does
little when there is a mapped superclass with foreign keys as part of a many to one
relationship.
Certain default strategies could be provided out of the box. The following example shows
certain defaults that may be usefull:
@Entity
class AlphaBeta {
@ManyToOne Delta getDelta() { }
}
1. StandardNamingStrategy - FK365FA4BB24B1D45C
Utilize a unique hash
2. SimpleNamingStrategy - fk_alpha_beta_delta
Convert camel case names into underscore delimited names appending the method name
3. SimpleCountingNamingStrategy - fk_alpha_beta_1
Convert camel case names into underscore delimited names appending a method counter
- Concern: What determines order? Order in the class, naming order, annotation?
4. VowelNamingStrategy - fk_alph_bt
Remove all vowels that are not on the leading edge of a camel case delimited by an
underscore
While the total length is greater than 16, chop the last letter of each word starting with
the longest and working from the right to the left
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