hibernate多表查询结果集的取值

多表查询hql语句:

select * from sys_prsnl as sys,cust_card as card  where sys.prsnl_id=card.cust_id
and prsnl_id in

(select cust_id from cust where cust_grd in ('01','02')) and card.status='B'

hibernate代码:

StringBuffer hql = new StringBuffer();
        hql.append("from Sys_prsnl as sys,Cust_card as card where sys.prsnl_id=card.cust_id")
            .append(" and prsnl_id in ")    
            .append("(select cust_id from Cust where cust_grd in ('01','02')) and card.status='A'");
        Session session  = HibernateSessionFactory.getSessionFactory().openSession();
        Transaction transaction = session.beginTransaction();
        Query query = session.createQuery(hql.toString());
        List<Object> objlist = query.list();
        System.out.println("查询结果"+objlist);
        for(Object obj:objlist){
            Object[] objs = (Object[])obj;
            System.out.println("将object拆分为objs数组后的长度:"+objs.length);
            System.out.println("将object拆分为objs数组后的打印:"+objs[0]);
            System.out.println("将object拆分为objs数组后的打印:"+objs[1]);
        }

        transaction.commit();
        session.close();

我做测试时后台打印的结果:

查询结果[[Ljava.lang.Object;@fb6354, [Ljava.lang.Object;@364641]
将object拆分为objs数组后的长度:2
将object拆分为objs数组后的打印:com.lige.note.dto.Sys_prsnl@1a897a9
将object拆分为objs数组后的打印:com.lige.note.dto.Cust_card@90832e
将object拆分为objs数组后的长度:2
将object拆分为objs数组后的打印:com.lige.note.dto.Sys_prsnl@1947496
将object拆分为objs数组后的打印:com.lige.note.dto.Cust_card@1724a9d

然后将objs[0]和objs[1]进行强制转换


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值