【发布时间】:2021-06-18 15:12:21
【问题描述】:
我要实现表之间的Join:
@Table(name = "users")
public class Users implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;
@Column(length = 255)
private String login;
}
@Table(name = "transactions")
public class Transactions implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;
@Column(name = "user_id", length = 20)
private Integer userId;
}
使用 login 我想从表 users 中选择引用 id 并将其映射到 userId 并列出与表 Transactions 中的 id 匹配的应用行。
我试过这个 HQL 查询:
SELECT c FROM Users u LEFT JOIN Transactions t ON u.id = t.id;
我不清楚如何选择合适的login 到id。你能指导我吗?
【问题讨论】:
标签: sql hibernate spring-data-jpa spring-data hql