[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4329) @ForeignKey override of @MappedSuperclass

David D (JIRA) noreply at atlassian.com
Wed Sep 15 03:15:28 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38393#action_38393 ] 

David D commented on HHH-4329:
------------------------------

My "workaround", which is more a best practice in my opinion : generate the schema with hbm2ddl and change any fk name you like (or any constraint name for the matter). Then use this file to create your database. But that's maybe not what you want to hear...

> @ForeignKey override of @MappedSuperclass
> -----------------------------------------
>
>                 Key: HHH-4329
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4329
>             Project: Hibernate Core
>          Issue Type: New Feature
>          Components: annotations
>            Reporter: Christian Bauer
>
> Put this @ManyToOne in a @MappedSuperclass:
>     @ManyToOne(fetch = FetchType.LAZY)
>     @JoinColumn(name = "CREATED_BY_USER_ID", nullable = false)
>     // Ideally this foreign key should be ON DELETE SET NULL, however...
>     // Hibernate can't rename these so subclasses would get the same FK constraint name. This doesn't
>     // work, so we need to let Hibernate create a random identifier for these. We could fix this in the
>     // DatabaseObjects.hbm.xml file but we can't even address it because the name is random. This sucks.
>     // So we do a manual SET NULL|DEFAULT when userHome.remove() is called.
>     // @org.hibernate.annotations.ForeignKey(name = "FK_WIKI_NODE_CREATED_BY_USER_ID")
>     protected User createdBy;
> Now all subclasses get that foreign key constraint name in the database catalog, which isn't possible - constraint names have to be unique. 

-- 
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