我有2个实体
public class EstMast implements java.io.Serializable {
private Long estCode;
private String estName;
private String estName;
private Long esttypeCode;
private String activeYn;
}
public class DisabEst implements Serializable {
private static final long serialVersionUID = 1L;
private long runId;
private Long estCode;
private Long regionCode;
private String spec;
}
如果输入2不为null,我需要执行条件查询我需要执行此查询
SELECT est FROM EstMast est, DisabEst dis WHERE est.estCode = dis.estCode AND est.esttypeCode =:input1
如果输入2存在,我需要附加一个AND查询(AND spec IN(:input2)),查询如下所示
SELECT est FROM EstMast est, DisabEst dis WHERE est.estCode = dis.estCode AND est.esttypeCode =:input1 AND spec IN (:input2)
如何使用hibernate条件动态查询来实现这一目标?
到目前为止我尝试了什么:
我开始使用标准。
Criteria accountCriteria = getCurrentSession().createCriteria(EstMast.class,"est");
这里如何添加第二个表?