我有 2 个实体
PayoutHeader.java
@Entity
public class PayoutHeader extends GenericDomain implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private Integer month;
@Column
private Integer year;
@OneToOne
private Bank bank;
@Column
private Double tdsPercentage;
@Temporal(javax.persistence.TemporalType.DATE)
private Date **chequeIssuedDate**;
@Temporal(javax.persistence.TemporalType.DATE)
private Date entryDate;
}
支付明细.java
@Entity
public class PayoutDetails {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
private PayoutHeader payoutHeader;
@Column
private Double amount;
@Column
private String bankName;
@Temporal(javax.persistence.TemporalType.DATE)
private Date clearingDate;
@OneToOne
private Advisor advisor;
@Column
private Long **advisorId**;
}
我想使用 Hibernate Criteria 编写查询,例如
Select pd.* from PayoutDetails pd, PayoutHeader ph where pd.payoutheaderId = ph.id and pd.advisorId = 1 and and ph.chequeIssuedDate BETWEEN STR_TO_DATE('01-01-2011', '%d-%m-%Y') AND STR_TO_DATE('31-12-2011', '%d-%m-%Y') ";
我写过这样的查询
public List<PayoutDetails> getPayoutDetails(AdvisorReportForm advisorReportForm) {
Criteria criteria = getSession().createCriteria(PayoutDetails.class);
if (advisorReportForm.getAdvisorId() != null && advisorReportForm.getAdvisorId() > 0) {
criteria.add(Restrictions.eq("advisorId", advisorReportForm.getAdvisorId().toString()));
}
criteria.setFetchMode("PayoutHeader", FetchMode.JOIN)
.add(Restrictions.between("chequeIssuedDate", advisorReportForm.getFromDate(), advisorReportForm.getToDate()));
return criteria.list();
}
但是给出错误为
org.hibernate.QueryException:无法解析属性:chequeIssuedDate of:org.commission.domain.payout.PayoutDetails
我认为是试图在 中查找chequeIssuedDate
字段PayoutDetails
,但该字段在PayoutHeader
. 如何在加入期间指定别名?