关于HQL语句的表链接查询

来源:百度知道 编辑:UC知道 时间:2024/06/17 19:53:50
business的主键是bid,contact的属性bid对应business.bid,现在进行一个查询,输入一个business.bname的值,进行查找,写了如下代码,应该怎么修改啊?
public ActionForward queryContact(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
List list = objectDao.getObjectList("from ContactForm");
if(request.getParameter("bname")!=null){
String bname= request.getParameter("bname");
list = objectDao.getObjectList("from ContactFrom b where b.bid=(select bid from BusinessFrom c where c.bname like '%"+bname+"%')");
request.setAttribute("result1",bname);
}
if(request.getParameter("conname")!=null){
String conname= request.getParameter("conname");
list = objectDao.getObjectList("from ContactForm c where c.conname like '%"+conname+"%'");
request.setAttribute("result2",conname);
}<

我以前好像是这样写的
select b from ContactFrom b,BusinessFrom c where b.bid = c.bid
记不大清楚了,不晓得对不

最好在其他论坛查一下,这个问题如果光是指出来你以后也不会弄