-->
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.  [ 2 posts ] 
Author Message
 Post subject: query result to class object
PostPosted: Wed Feb 21, 2007 6:56 am 
Newbie

Joined: Mon Feb 19, 2007 1:44 am
Posts: 8
Hi,

I am using the HQL query

select ct.id, ct.firstName from Contact ct

I am querying only 2 fields where there are 4 fields in the table.

So I cannot use the following code since number of elements in the class and query does not match

Contact ct=(Contact)it.next();
System.out.println("ID: " + ct.getId());
System.out.println("First Name: " + ct.getFirstName());

where Contact is the classname and 'it' is an iterator object

I know how to do it with object array.

But I want to know is there any method or API using that I can still use an object of the 'Contact' class to store the result and show the values using getter methods?

Thanks and Regards,
Jacob Baby


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 7:27 am 
Newbie

Joined: Fri Feb 02, 2007 8:19 am
Posts: 5
HQL allows you to return Objects you specify..

If Contact has an appropriate constructor, you can try the following:

select new Contact(ct.id, ct.firstName) from Contact ct

this should give you a Contact-Object filled with id and firstName.

Edit: On a second thought... maybe won't work, as you don't want one result only...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.