JPA:外键注释 [英] JPA: foreign key annotation

查看:151
本文介绍了JPA:外键注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据库实体:论坛主题

I've got two database entities: Forum and Topic.

主题 protected long forumId data member,which表示当然主题的论坛。

Topic has protected long forumId data member, which indicates of course the Topic's forum.

我的问题是这个数据成员使用什么注释?

My question is what annotation to use for this data member?

推荐答案

p>由于论坛有许多主题,而且一个主题属于唯一的论坛,您可能希望使用 @ManyToOne

As Forum has many topics, and a topic belongs to one and only Forum, you probably want to go with a Forum type attribute annotated with @ManyToOne:

@ManyToOne
@JoinColumn(name = "forumId")
private Forum forum;

查看更多:

ManyToOne JPA映射

这篇关于JPA:外键注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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