-->
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.  [ 4 posts ] 
Author Message
 Post subject: what is returned in the below HQL Query?
PostPosted: Wed Apr 07, 2010 6:58 pm 
Newbie

Joined: Thu Mar 11, 2010 12:55 am
Posts: 4
Hi,

I am executing the below HqL query--

select v.visitId as visitId, max(v.startDt) as startDt
from com.zts.hygeia.dao.Visit as v
where (v.visitStatus!='SC' or v.visitStatus!='CL')
and v.visitType.visitCategory='ENC'
and v.patient.patientId = :patientId
group by v.visitId


It is returning a list of objests. and I need to get the values in a object . I tried casting it to a custom class with integer and date stamp still it can't do it.

Any suggestions


Top
 Profile  
 
 Post subject: Re: what is returned in the below HQL Query?
PostPosted: Thu Apr 08, 2010 5:08 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
AshwinD wrote:
It is returning a list of values. and I need to get the values in a object . I tried casting it to a custom class with integer and date stamp still it can't do it.
Any suggestions

I think if you want to do this you need to make an object that matches what you select in the query.
I don't think Hibernate is very useful in this case.


Top
 Profile  
 
 Post subject: Re: what is returned in the below HQL Query?
PostPosted: Thu Apr 08, 2010 5:50 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
this query returns a list of Object[]

Object[] row = (Object[])result.get(0);
Integer number = (Integer)row[0]; //visitId
Date order = (Date)row[1]; //startDt

You can also use a 'new' syntax in your query to obtain a result of Object (not array)...like that the query returns a list of "instance of your class"
Code:
SELECT new MyResult(v.visitId, max(v.startDt)) FROM ...

of course class MyResult must declare a constructor where the type of parameters is the same type of returned field in select clause.

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: what is returned in the below HQL Query?
PostPosted: Thu Apr 08, 2010 11:20 am 
Newbie

Joined: Thu Mar 11, 2010 12:55 am
Posts: 4
got it

Thanks .


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