RaviChandra T:
CPT表
@Entity
@Table(name = "CPT")
public class CPTCodeset {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private int id;
@Column(name = "Code")
private String code;
@Column(name = "Description")
private String desc;
//getters and setters
}
CPTの手順表
@Entity
@Table(name = "cptprocedures")
public class CPTProcedures {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private int Id;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "ProcedureId")
private Procedure procedure;
@Transient
private int procedureId;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "CPTCodeSet")
private CPTCodeset cpt;
@Transient
private int cptCodeSet;
//getters and setters
}
CPTRepository
@Query(nativeQuery = true, value = "SELECT cp.ProcedureId,c.Code,c.Description FROM cptprocedures cp JOIN CPT c ON cp.CPTCodeSet = c.Id where c.Description like \"%ane\";")
List<CPTCodeset> findBySearch(@Param("searchString") String searchString);
データを返すこのクエリは、私が欲しいものです。しかし、どのように私はそれが2つのテーブルを含んでいるとして、1つのオブジェクトにこのデータをマッピングすることができます。
どのように私は使用してそれを行うことができ@Entity
、テーブルを作成しません。助言がありますか?
Fereydoun:
@Query("SELECT new com.dto.ProduceCPT(cp.ProcedureId, c.Code, c.Description) FROM cptprocedures cp JOIN CPT c ON cp.CPTCodeSet = c.Id where c.Description like \"%ane\" ")
List< ProduceCPT> fetchProduceCPT();