gpt4 book ai didi

java - CrudRepository 通过自定义联接字段过滤器查找

转载 作者:行者123 更新时间:2023-12-01 19:54:21 26 4
gpt4 key购买 nike

我有以下实体

  1. 请求对象
  2. AdditionalReqObj。

两个实体均与 REQ_ID 链接表中的列(reqId 字段)。我正在使用Spring data CrudRepository interface用于存储库。

现在我想要findAll RequestObj entity通过REQUEST.REQ_STATUS这是开放的 & 链接 其他请求也应按 ADDL_REQUEST.ADD_REQ_STATUS 进行过滤

@Entity
@Table(name = "REQUEST")
public class RequestObj implements Serializable {

@Id
@Column(name = "REQ_ID")
private long reqId;

@Column(name = "REQ_NM")
private String reqUserNm;

@Column(name = "REQ_EMAIL")
private String reqUserEmail;

@Column(name = "REQ_ID")
private String reqComments;

@Column(name = "REQ_STATUS")
private String reqStatus;

@OneToMany(mappedBy = "request", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<AdditionalReqObj> requestDtls;

---getter setter----
}

@Entity
@Table(name = "ADDL_REQUEST")
public class AdditionalReqObj implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name = "AdD_REQ_ID")
private long addReqId;

@Column(name = "ROLE_NM")
private String add_req_comment;

@ManyToOne
@JoinColumn(name = "REQ_ID")
private RequestObj request;

@Column(name = "ADD_REQ_STATUS")
private String addReqStatus;

---getter setter----
}

最佳答案

您必须在您的方法上触发 native 查询。你可以这样做,

@Query(value = "SELECT R.* FROM REQUEST R INNER JOIN ADDL_REQUEST AR ON R.REQ_ID = AR.REQ_ID WHERE R.REQ_STATUS = :PARAM1 and AR.ADD_REQ_STATUS = :PARAM2 ", nativeQuery = true)
List<ReqObj> findAllByAddressId(Object PARAAM1, Object PARAM2);

关于java - CrudRepository 通过自定义联接字段过滤器查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59053367/

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