大家帮我看看这个dao 中通过外键查询HQL是怎样写的,先谢谢了
我现在的dao中是这样写的public List findByShebei(Shebei sb) {
log.debug("getting Shebeibj instance with shebei: " +sb );
try {
List results = (List) getSession().get(
"com.hanke.dao.Shebeibj", sb);
return results;
} catch (RuntimeException re) {
log.error("find by shebei failed", re);
throw re;
}
}
说我的查询失败
我的shebeibj的实体是这样写的
public class Shebeibj implements java.io.Serializable {
// Fields
private String shebeibjid;
private Shebei shebei;
private String bjname;
private Integer qty;
private Date date;
private String remark;
// Constructors
/** default constructor */
public Shebeibj() {
}
/** minimal constructor */
public Shebeibj(String shebeibjid, Shebei shebei, String bjname) {
this.shebeibjid = shebeibjid;
this.shebei = shebei;
this.bjname = bjname;
}
/** full constructor */
public Shebeibj(String shebeibjid, Shebei shebei, String bjname,
Integer qty, Date date, String remark) {
this.shebeibjid = shebeibjid;
this.shebei = shebei;
this.bjname = bjname;
this.qty = qty;
this.date = date;
this.remark = remark;
}
// Property accessors
public String getShebeibjid() {
return this.shebeibjid;
}
public void setShebeibjid(String shebeibjid) {
this.shebeibjid = shebeibjid;
}
public Shebei getShebei() {
return this.shebei;
}
public void setShebei(Shebei shebei) {
this.shebei = shebei;
}
public String getBjname() {
return this.bjname;
}
public void setBjname(String bjname) {
this.bjname = bjname;
}
public Integer getQty() {
return this.qty;
}
public void setQty(Integer qty) {
this.qty = qty;
}
public Date getDate() {
return this.date;
}
public void setDate(Date date) {
this.date = date;
}
public String getRemark() {
return this.remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
} --------------------编程问答-------------------- List results = (List) getSession().get(
"com.hanke.dao.Shebeibj", sb);这个方法,我记得是更具sb映射文件的主键去查询吧。。。
在这儿你的主键要是已经确定来的、才能查询到。 --------------------编程问答-------------------- shebei表中的主键是shebeiid 是这个表 shebeibj表中的外键, 那么我现在应该怎样做呢? --------------------编程问答-------------------- 用query方法,直接写hql,跟sql差不多 --------------------编程问答--------------------
ding
补充:Java , Web 开发