-->
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: HQL query with entities and scalar values
PostPosted: Tue Aug 18, 2009 2:02 pm 
Is it possible to write an JPQL/HQL query that has entities *and* scalar values in the select clause?

Code:
select c.customerId,
         a
from   Customer c,
         Address a
where c.addressId = a.addressId


So c.customerId is a scalar value and a is the Address entity. I'm assuming if this is legal, then the resultset is a List<Object[]> instance. correct?

I should just try it to see what happens...


Top
  
 
 Post subject: Re: HQL query with entities and scalar values
PostPosted: Tue Aug 18, 2009 3:52 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
That's right.
//somehow get the session.
List<Object[]> objects =session.createQuery("select c.customerId,
a
from Customer c,
Address a
where c.addressId = a.addressId").list();

where each object array will have
Object[0] --Long(assuming the customerId is mapped to Long.)
Object[1] -- Instance of Address.

-Srilatha.


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.