When specifying a unique constraint on a join table, if the columns of the constraint match that of the primary key generated for the join table, the unique constraint will be removed based on the following documentation in {{org.hibernate.mapping.Table#cleanseUniqueKeyMap()}}: {code} // We need to account for a few conditions here... // 1) If there are multiple unique keys contained in the uniqueKeys Map, we need to deduplicate // any sharing the same columns as other defined unique keys; this is needed for the annotation // processor since it creates unique constraints automagically for the user // 2) Remove any unique keys that share the same columns as the primary key; again, this is // needed for the annotation processor to handle @Id @OneToOne cases. In such cases the // unique key is unnecessary because a primary key is already unique by definition. We handle // this case specifically because some databases fail if you try to apply a unique key to // the primary key columns which causes schema export to fail in these cases. {code}
For situations where a unique constraint has a user specified name and the columns map to those of the join-table's primary key, allow that constraint name to influence the primary key's name instead.
We should document this and clearly indicate that depending on the dialect, some databases don't permit named primary keys and in those cases, the name will still be dropped and ignored.
We should add a log warning about this naming so they're aware what we've done but recommend that they instead use the explicit approach determined by HHH-11527. |
|