用jpa创建外键 [英] Create foreign key with jpa

查看:1384
本文介绍了用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.

如您所见,我同时具有ManyToOneOneToMany批注,但尚未创建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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆