0

我想将以下查询转换为 HQL:

SELECT C.ID, E.DESCRIPTION as STATUS, E1.DESCRIPTION as SUBJECT
FROM CRED C 
join CODE_EVN E
ON E.CODE = C.STATUS_CODE
AND E.SUBCODE =  C.STATUS_SUBCODE 
join CODE_EVN E1
ON E1.CODE = C.SUBJECT_CODE
AND E1.SUBCODE =  C.SUBJECT_SUBCODE

我有两个类 User 和 Codes,它们之间没有映射,那么如何在 Hibernate 中执行以下查询?我尝试了很多东西,但似乎没有任何效果

这些是我的 2 个 bean 类:

用户等级:

@Entity
@Table(name="CRED")
public class User {

    private String id;
    private String STATUS_CODE;
    private String STATUS_SUBCODE;
    private String SUBJECT_CODE;
    private String SUBJECT_SUBCODE;


    @Id
    @Column(name="ID")  
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }

    public void setSTATUS_CODE(String sTATUS_CODE) {
        STATUS_CODE = sTATUS_CODE;
    }
    public String getSTATUS_CODE() {
        return STATUS_CODE;
    }

    public void setSTATUS_SUBCODE(String sTATUS_SUBCODE) {
        STATUS_SUBCODE = sTATUS_SUBCODE;
    }
    public String getSTATUS_SUBCODE() {
        return STATUS_SUBCODE;
    }

    public void setSUBJECT_CODE(String sUBJECT_CODE) {
        SUBJECT_CODE = sUBJECT_CODE;
    }
    public String getSUBJECT_CODE() {
        return SUBJECT_CODE;
    }

    public void setSUBJECT_SUBCODE(String sUBJECT_SUBCODE) {
        SUBJECT_SUBCODE = sUBJECT_SUBCODE;
    }
    public String getSUBJECT_SUBCODE() {
        return SUBJECT_SUBCODE;
    }

}

代码类:

 @Entity
    @Table(name="CODE_EVN")
public class Codes {
    @Id
    private String CODE;

    private String SUBCODE;
    private String DESCRIPTION;

    public void setCODE(String cODE) {
        CODE = cODE;
    }
    public String getCODE() {
        return CODE;
    }

    public void setSUBCODE(String sUBCODE) {
        SUBCODE = sUBCODE;
    }
    public String getSUBCODE() {
        return SUBCODE;
    }

    public void setDESCRIPTION(String dESCRIPTION) {
        DESCRIPTION = dESCRIPTION;
    }
    public String getDESCRIPTION() {
        return DESCRIPTION;
    }
}
4

0 回答 0