0
的條件查詢我有兩個類:休眠新手:多個相關的類
@Entity
@Table(name = "Appeal_Header")
public class AppealHeader implements Serializable {
private static final long serialVersionUID = -8402922611571578104L;
@Id
@Column(name = "Appeal_Header_Key", unique=true, nullable=false)
private long id;
@Column(name = "customer_cd", unique=true, nullable=false)
private String customer;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="hes_invoice_header_id", insertable=false)
private BillingHeader billingHeader;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public BillingHeader getBillingHeader() {
return billingHeader;
}
public void setBillingHeader(BillingHeader billingHeader) {
this.billingHeader = billingHeader;
}
public String getCustomer() {
return customer;
}
public void setCustomer(String customer) {
this.customer = customer;
}
}
@Entity
@Table(name = "billing_header")
public class BillingHeader implements Serializable {
private static final long serialVersionUID = 503665425710114912L;
@Id
@Column(name="hes_invoice_header_id", insertable=false, updatable=false)
private long id;
@Column(name="claim_number", insertable=false, updatable=false, unique=false)
private String claimNumber;
@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="hes_invoice_header_id", insertable=false, updatable=false)
private List<AppealHeader> appealHeader;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getClaimNumber() {
return claimNumber;
}
public void setClaimNumber(String claimNumber) {
this.claimNumber = claimNumber;
}
public List<AppealHeader> getAppealHeader() {
return appealHeader;
}
public void setAppealHeader(List<AppealHeader> appealHeader) {
this.appealHeader = appealHeader;
}
}
public void exececute() {
Criteria criteria = session.createCriteria(AppealHeader.class);
if(!"".equals(form.getCustomer()))
criteria.add(Restrictions.eq("customer",form.getCustomer()));
if(!"".equals(form.getClaimNumber()))
criteria.add(Restrictions.eq("billingHeader.claimNumber",form.getClaimNumber()));
}
現在,我執行這個條件查詢:
如果我通過客戶查詢我找回所有的申訴頭記錄加上關聯的帳單標題。但是,如果我查詢客戶和billingHeader.claimNumber只是billingHeader.claimNumber單獨。我得到這個例外:
Exception: org.hibernate.QueryException: could not resolve property: billingHeader.claimNumber of: healthe.appeals.model.AppealHeader
有人能幫我嗎?
Paulo, 感謝您給我指出正確方向的答案。這些限制是在頁面底部的代碼痛苦中定義的。我想這和它的接縫的工作:(! 「」 等於(form.getAppealHeaderKey())。) criteria.add(Restrictions.eq( 「 如果ID」 的Long.parseLong(form.getAppealHeaderKey())) );如果(!「」。equals(form.getCustomer())) criteria.add(Restrictions.eq(「customer」,form.getCustomer())); if(!「」。equals(form.getClaimNumber())) criteria.createCriteria(「billingHeader」)。add(Restrictions.eq(「claimNumber」,form.getClai –