-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: return multiple columns ?
PostPosted: Sun Nov 01, 2009 10:06 pm 
Newbie

Joined: Mon Jul 09, 2007 9:32 am
Posts: 17
if I have a query, like "select c1, c2, c3 from myTable", then which method I should use to return multiple columns ?

Thanks.


Top
 Profile  
 
 Post subject: Re: return multiple columns ?
PostPosted: Mon Nov 02, 2009 2:14 am 
Newbie

Joined: Fri Sep 05, 2008 2:08 am
Posts: 7
@ czy11421

List result = session.createQuery("select c1, c2, c3 from myTableBean").list();
It will working fine.In my application i have written code for similar task.

Code:
public List listAllEmp(){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
       
        List result = session.createQuery("from empBean.Employee").list();
        session.getTransaction().commit();
        System.out.println("end of listAllEmp method");
        return result;
    }


Last edited by sreedhar.en on Mon Nov 02, 2009 7:13 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: return multiple columns ?
PostPosted: Mon Nov 02, 2009 3:28 am 
Newbie

Joined: Thu Mar 08, 2007 8:49 am
Posts: 11
Location: Hyd
select c1, c2, c3 from myTable
returns in object array
Object[] arrObjQuerydtls
arrObjQuerydtls[0] -- c1 value, arrObjQuerydtls[1] -- c2 value, arrObjQuerydtls[2] -- c3 value

You can use query interface uniqueResult() or list() methods

List result = session.createQuery("select empid,empname,sal from empBean.Employee").list();
returns list of object arrays

Regards
Sunil K

_________________
Thanks&Regards
Sunil k


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.