[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-3532) schema update task should look for foreign key signature

Steve Ebersole (JIRA) noreply at atlassian.com
Mon Jun 1 17:32:14 EDT 2009


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Steve Ebersole updated HHH-3532:
--------------------------------

         Priority: Minor  (was: Critical)
         Assignee: Steve Ebersole
    Fix Version/s: 3.5

> schema update task should look for foreign key signature
> --------------------------------------------------------
>
>                 Key: HHH-3532
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3532
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: metamodel
>    Affects Versions: 3.3.1
>            Reporter: Dan Allen
>            Assignee: Steve Ebersole
>            Priority: Minor
>             Fix For: 3.2.x, 3.3.x, 3.5
>
>         Attachments: HHH-3532-3.2.x.patch, HHH-3532.patch
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When the schema update task runs, it attempts to locate a foreign key in the database that matches the name provided in the Hibernate mapping information for that particular association. (The name of the foreign key is specified either in the foreign-key attribute in a mapping file or the @ForeignKey annotation). That much works fine. It's when a foreign key name is not provided, common in the case when standard JPA mappings are used, that problems arise.
> When a foreign key name is not provided, Hibernate generates a key name as follows:
> "FK" + hash code of referenced entity name + hash codes of columns
> The chances of an existing foreign key in the database using this generated name is slim to none (every DBA has their own conventions that they follow). Thus, as soon as the scheme update task hits a database under these conditions, duplicate foreign key definitions appear all over the place.
> If a foreign key name is not provided in the mapping, Hibernate should be looking instead to see if the signature of the foreign key matches that which is required to fulfill the mapping. In fact, I would even argue that the name is irrelevant and should only be used when actually *creating* the foreign key.
> Here is the existing logic in the generateSchemaUpdateScript in Configuration:
> ForeignKey fk = (ForeignKey) subIter.next();
> boolean create = tableInfo == null || tableInfo.getForeignKeyMetadata( fk.getName() ) == null;
> It should be like this instead:
> ForeignKey fk = (ForeignKey) subIter.next();
> boolean create = tableInfo == null || tableInfo.getForeignKeyMetadata( fk ) == null;
> getForeignKeyMetadata should retrieve based on the fk signature rather than the fk name.

-- 
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list