Is the ForeignKey annotation only used by HBM2DDL to generate the schema?

≯℡__Kan透↙ 提交于 2019-12-11 11:33:37

问题


I'm having an issue with how Hibernate generates foreign key names when using the TABLE_PER_CLASS inheritance strategy: Foreign keys have random number appended when using Hibernate's TABLE_PER_CLASS inheritance

So I'm wondering if I can simply replace the annotation with the following:

@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Entity
abstract class Item {
    @ManyToOne
    @ForeignKey(name="FK_ITEM_ORG_CHANGEME")
    @JoinColumn(name="ORG_ID")
    private Organization org
}

That way I always know to go back to the generated DDL and replace all occurrences of CHANGEME. Does Hibernate do anything else with the @ForeignKey attribute that I'm not aware of or is this a good workaround?


回答1:


Possible, you could redefine such behavior via own Naming staretgy - http://docs.jboss.org/hibernate/core/3.2/api/org/hibernate/cfg/NamingStrategy.html#foreignKeyColumnName(java.lang.String, java.lang.String, java.lang.String, java.lang.String) ?




回答2:


That's correct, @ForeignKey is only used by HBM2DDL (or its little brother that generate a domain model from an existing database but you are not using that it seems).



来源:https://stackoverflow.com/questions/6683757/is-the-foreignkey-annotation-only-used-by-hbm2ddl-to-generate-the-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!