鉴于下面的 JPA 实体,我想获取所有具有至少一个成功状态的请求的借记。
可以有许多具有相同 debit_id 和不同状态的请求
我应该使用这样的东西还是有更好的做事方式
entityManager.createQuery("select c from Debit d join d.id where request.status =Succesful"
@Entity(name = "T_DEBIT")
public class Debit {
public enum Status { NEW, OLD }
@Column(name = "STATUS", nullable = false, length = 20)
@Enumerated(value = EnumType.STRING)
private Status status;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "ACCOUNT_ID", updatable = false, nullable = false)
private Account account;
}
和其他实体是
@Entity(name = "T_REQUEST")
public class Request{
public enum Status { PENDING, FAILED, SUCCESFUL}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "DEBIT_ID", updatable = false, nullable = false)
private Debit debit;
@Column(name = "STATUS", nullable = false, length = 20)
@Enumerated(value = EnumType.STRING)
private Status status;
}
如果缺少任何内容,请发表评论,而不是关闭或否决问题!