hibernate 查询

查询两个对象


public List showAttchment(String cd_ssdw,String wblb)
{
//String queryString = "select attch.attachid,attch.wjmc from gh_pub_text text,gh_pub_attach attch where text.cd_ssdw="+cd_ssdw+" and text.wbid=attch.lybpk";
String queryString = "select attch.attachid,attch.wjmc,attch.wjhz from GhPubAttach attch,GhPubText text where text.cdSsdw="+cd_ssdw+" and text.wblb="+wblb+" and text.wbid=attch.lybpk";
List objList = new ArrayList();
List temp = new ArrayList();
temp = this.findAll(queryString);
if(temp.size()!=0)
{

for(int i=0;i<temp.size();i++)
{
GhPubAttach attch = new GhPubAttach();
Object []obj= (Object[])temp.get(i);
Long id = (Long)obj[0];
String wjmc = (String)obj[1];
String wjhz = (String)obj[2];
attch.setAttachid(id);
attch.setWjmc(wjmc);
attch.setWjhz(wjhz);
objList.add(attch);
}

}



return objList;
}


查询一个对象

public List<GhPubText> getGhbgObject(String wblb,String cdSsdw,String year)
{
List<GhPubText> list = new ArrayList<GhPubText>();
GhPubText ghGhbgText = new GhPubText();

String query = "select t from GhPubText t where t.wblb="+wblb+" and t.cdSsdw="+cdSsdw+"";
if(!"".equals(year)&&year!=null)
{
query = "select t from GhPubText t where t.wblb="+wblb+" and t.cdSsdw="+cdSsdw+" and t.year="+year+"";
}
List temp = new ArrayList();
temp = this.findAll(query);
if(temp.size()!=0)
{
Object ob = temp.get(0);
GhPubText ghbg = (GhPubText)ob;
ghGhbgText.setNr1(ghbg.getNr1());
ghGhbgText.setNr2(ghbg.getNr2());
ghGhbgText.setWbid(ghbg.getWbid());
ghGhbgText.setWblb(ghbg.getWblb());
//ghGhbgText.setBqid(ghbg.getBqid());
//ghGhbgText.setSchemeId(ghbg.getSchemeId());
list.add(ghGhbgText);
}
return list;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值