用jpa创建外键 [英] Create foreign key with jpa
问题描述
因此,当我运行项目时,会创建User
表和Doc
表,但是在Doc
表中没有看到User
表的外键.
So when I run my project the User
table and the Doc
table are created, but I dont see the foreign key for User
table in the Doc
table.
如您所见,我同时具有ManyToOne
和OneToMany
批注,但尚未创建User的外键.
As you can see I have both ManyToOne
and OneToMany
annotations, and yet the foreign key for User isn't created.
我该如何解决?
推荐答案
您需要添加@JoinColumn(name ="ID Column Name")批注以及@ManyToOne或@OneToMany批注,如ZaoTaoBao所述.此批注确定将用作FK的列的名称.
You need to add @JoinColumn(name = "ID Column Name") annotation along with the @ManyToOne or @OneToMany annotation as ZaoTaoBao mentioned. This annotation determines the name of the column which is to be used as FK.
有关更多详细信息,请参考此链接: http://docs.oracle.com/javaee/6/api/javax/persistence/JoinColumn.html
Refer to this link for more details: http://docs.oracle.com/javaee/6/api/javax/persistence/JoinColumn.html
这篇关于用jpa创建外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!