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]进行强制转换


你可能感兴趣的:(Hibernate)