Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2074

Create foreign key with jpa

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.

As you can see I have both ManyToOne and OneToMany annotations, and yet the foreign key for User isn't created.

How can I solve this ?

Upvotes: 1

Views: 515

Answers (1)

ritesh.garg
ritesh.garg

Reputation: 3943

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.

Refer to this link for more details: http://docs.oracle.com/javaee/6/api/javax/persistence/JoinColumn.html

Upvotes: 1

Related Questions