[hibernate-dev] Constraint naming in HBM2DDL schema export

"Jürgen Avian" javian at gmx.net
Fri Oct 31 03:39:51 EDT 2008


some time ago I added the following feature to the Hibernate Core:

Automated naming of the constraint types in the hbm2ddl schema export (naming scheme in brackets)

  - Primary Key Constraints (PK_<TABLENAME><IDX>)
  - Unique Constraints (UK_<TABLENAME><IDX>_<COLUMNNAME><IDX>)
  - Check Constraints (<CT>_<TABLENAME><IDX>_<COLUMNNAME><IDX>)
  - Foreign Key Constraints (FK_<TABLENAME><IDX>_<COLUMNNAME><IDX>)

  <CT> for unique constraints is one of:

    - NN for Not Null Constraints
    - CK for other Check Constraints
  <IDX> is an index that is needed if the table or
  column name has to be shortened because of a maximal
  length of the constraint name in the database.

At the moment, I have implemented it in the following way:

  - The constraint names are generated in the dialect.
  - Constraint naming can be turned on and off in the
    config file (persistence.xml).
  - Via the config file you can specify a character
    that is removed from the table and column names to
    improve the constraint name length utilization,
    e.g. COMPANY_DETAILS can be reduced to COMPANYDETAILS
  - The maximal constraint name length can be specified
    in the config file as well.

That way, it is possible to identify the reason for a constraint violation much more easier. Additionally, you have not to be at the mercy of the database constraint naming schema.

Is something similar implemented at the moment by anyone?

I would be pleased if you like to add this functionality to the hibernate sources.

In this case I would adapt my implementation:

  - Create an own class e.g. DefaultConstraintNamingStrategy,
    according to the table and column NamingStrategy ...
  - ... that can be overwritten and plugged in via the
    config file.
What do you think about this idea?

Best regards,
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

More information about the hibernate-dev mailing list