如何在HQL中编写此SQL查询?

时间:2018-12-03 10:06:31

标签: java sql hql

我的SQL查询是:

SELECT DISTINCT(amndCanReqDtls.REQ_ID)       AS req_id,
  amndCanTypeMaster.AMND_CANC_DESC           AS amendmentType,
TO_CHAR(amndCanReq.REQ_DATE, 'dd/mm/yyyy') AS amedmentDate,
amndCanReqDtls.REMARKS                     AS amedmentRemarks,
amndCanReq.STATUS                          AS amedmentStatus
FROM PTAX_AMND_CANC_REQ amndCanReq
LEFT JOIN PTAX_AMND_CANC_REQ_DTLS amndCanReqDtls
ON amndCanReq.REQ_ID=amndCanReqDtls.REQ_ID
INNER JOIN PTAX_AMND_CANC_TYPE_MASTER amndCanTypeMaster
ON amndCanReqDtls.REQ_TYPE   =amndCanTypeMaster.AMND_CANC_ID
WHERE amndCanReq.ENROL_REG_NO='192000485748';

我的实体类是:

此类用于PTAX_AMND_CANC_REQ amndCanReq:

public class PTAX_AMND_CANC_REQ implements Serializable {

@Id
@Column(name = "REQ_ID")
private String reqID;
@Column(name = "ENROL_REG_NO")
private String enrolRegNO;
@Column(name = "STATUS")
private String status;
@Column(name = "PENDING_REASON")
private String pendngReason;
@Column(name = "REQ_DATE")
@Temporal(javax.persistence.TemporalType.DATE)
 private Date requstDt;

第二个实体calss是:

公共类PTAX_AMND_CANC_REQ_DTLS实现可序列化的{

@Id
@Column(name = "REQ_ID")
private String reqId;
@Column(name = "REQ_TYPE")
private String reqType;
@Column(name = "REMARKS")
private String remarks;
@Column(name = "COL_NAME")
private String colName;
@Column(name = "COL_VALUE")
private String colValue;

@ManyToOne
@JoinColumn(name = "REQ_TYPE", insertable = false, updatable = false)
private PTAX_AMND_CANC_TYPE_MASTER typeMaster;

如何使用DISTINCT加入两个实体?

0 个答案:

没有答案