是否仅由HBM2DDL使用ForeignKey注释来生成模式? [英] Is the ForeignKey annotation only used by HBM2DDL to generate the schema?
问题描述
在使用TABLE_PER_CLASS继承策略时,Hibernate如何生成外键名称存在问题:
我想知道是否我可以简单地用下面的代码来替换注释:
$ b $ p $ @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Entity
抽象类Item {
@ManyToOne
@ForeignKey(name =FK_ITEM_ORG_CHANGEME)
@JoinColumn(name =ORG_ID)
private Organization org
$ b
这样我总是知道回到生成的DDL并替换所有出现的改变我自己。 Hibernate是否使用我不知道的 @ForeignKey
属性来做任何其他的事情,或者这是一个很好的解决方法?
/cfg/NamingStrategy.html#foreignKeyColumnName(java.lang.Stringrel =nofollow> 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)?
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?
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) ?
这篇关于是否仅由HBM2DDL使用ForeignKey注释来生成模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!