如何在JPA实体中定义外键?

发布于 2025-02-10 01:41:02 字数 657 浏览 1 评论 0原文

我对客户表的创建有疑问。

CREATE TABLE `customer` (
 `cus_name` varchar(30) NOT NULL,
 `email` varchar(30) NOT NULL,
 `password` varchar(20) NOT NULL,
 `phone` varchar(15) NOT NULL,
 PRIMARY KEY (`email`)
)

我有第二个表格,它是带有电子邮件的外键的预订表查询,该键是从客户表中进行的。

CREATE TABLE `booking` (
 `booking_num` int(11) NOT NULL AUTO_INCREMENT,
 `pass_email` varchar(30) NOT NULL,
 `name` varchar(30) NOT NULL,
 `contact` varchar(20) NOT NULL,
 PRIMARY KEY (`booking_num`),
 CONSTRAINT `email_fk` FOREIGN KEY (`pass_email`) REFERENCES `customer` (`email`)
) 

如何制作JPA来创建执行创建表格的确切查询的表?

@Joincolumn注释和关系中会有什么?

谢谢。

I have a query for Customer table creation.

CREATE TABLE `customer` (
 `cus_name` varchar(30) NOT NULL,
 `email` varchar(30) NOT NULL,
 `password` varchar(20) NOT NULL,
 `phone` varchar(15) NOT NULL,
 PRIMARY KEY (`email`)
)

I have the second table which is the booking table query with a foreign key of email which is from customer table.

CREATE TABLE `booking` (
 `booking_num` int(11) NOT NULL AUTO_INCREMENT,
 `pass_email` varchar(30) NOT NULL,
 `name` varchar(30) NOT NULL,
 `contact` varchar(20) NOT NULL,
 PRIMARY KEY (`booking_num`),
 CONSTRAINT `email_fk` FOREIGN KEY (`pass_email`) REFERENCES `customer` (`email`)
) 

How do I make the JPA to create the tables that performs the exact query for creation of tables?

what would be in the @JoinColumn annotation and the relationship?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文