gpt4 book ai didi

spring - 在具有相似 ID 的 Spring Boot 中加入没有外键的两个表

转载 作者:行者123 更新时间:2023-12-05 03:55:46 25 4
gpt4 key购买 nike

这里我有两个表;两者都有 ID 作为主键。我想知道如何根据它们的 ID 在没有外键的情况下连接这些表。服务实现应该是什么,存储库中应该有什么?如何使用JOINS 编写@Query

@Entity
@Table(name = "procedures")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class Procedure implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ProcedureId")
private int id;

@Column(name = "ProcedureName")
private String name;
@Column(name = "ProcedureCode")
private String code;

@Column(name = "ProcedureDesc")
private String desc;
// getters and setters
}
@Entity
@Table(name = "cliniciandescriptor")
public class CPTClinicianDescriptor {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private int id;

@Column(name = "ConceptId")
private int conceptId;

@Column(name = "CPTCode")
private String cptCode;

@Column(name = "ClinicianDescriptorId")
private int clinicianDescriptorId;


@Column(name = "ClinicianDescriptor")
private String clinicianDescriptor;
// getters and setters
}

最佳答案

您可以像在 SQL 中一样使用 JOIN on 语法

例如

select p from Procedure p join CPTClinicianDescriptor c on c.id = p.id;

在此处阅读有关该主题的更多信息: https://72.services/how-to-join-two-entities-without-mapped-relationship/

关于spring - 在具有相似 ID 的 Spring Boot 中加入没有外键的两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59896488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com