私は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;
}
PayoutDetails .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**;
}
HibernateCriteriaを使用してクエリを記述したい
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
です。結合中にエイリアスを指定するにはどうすればよいですか?