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

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

问题描述

我有两个数据库实体:ForumTopic.

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

Topicprotected long forumId 数据成员,当然表示Topic 的论坛.

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?

推荐答案

由于论坛有很多主题,并且一个主题属于一个且唯一的论坛,您可能希望使用带有 @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;

查看更多:

ManyToOneJPA 映射

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

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