【发布时间】:2018-11-30 07:09:19
【问题描述】:
我在 MySQL 数据库中有 2 个表:user 和 user_additional_details,列如下所述。
用户
- id(自动递增)
- userId(唯一)
- 名字
- 姓氏
- 电话
- 电子邮件
用户其他详细信息
- id(自动递增)
- userId(与 User 中的 userId 匹配)
- 个人电话
- 个人邮箱
表 user_additional_details 为 user 表中的每个 userId 包含 0 或 1 行。
但是,数据库没有定义外键约束。理想情况下,来自user_additional_details 的列应该作为可空列添加到user 表中,但由于某些未知原因没有这样做。现在我需要为以下查询定义实体。
select user.userId, user.phone, user_a_d.personalPhone
from user
join user_additional_details as user_a_d
on user.userId = user_additional_details.userId
我尝试为表定义 JPA 实体,但无法弄清楚如何创建使用来自不同表的列的实体。
【问题讨论】:
-
为什么不能使用 JPQL 来获取 Object 数组中需要的数据?
-
@GarimaGupta 我是 JPA 的新手。你能举个例子吗?
标签: java mysql jpa spring-data-jpa persistence