使用条件和限制的休眠加入
2022-09-04 21:15:06
我有 2 个实体作为
支付标题.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**;
}
我想使用休眠条件编写查询,例如
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: 無法解析屬性: checkqueIssuedDate of: org.commission.domain.payout.PayoutDetails
我认为是试图在中找到字段,但是这个字段在.如何在加入过程中指定别名?chequeIssuedDate
PayoutDetails
PayoutHeader