-->
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.  [ 11 posts ] 
Author Message
 Post subject: Entity class required in createSQLQuery???
PostPosted: Tue Jul 12, 2005 2:02 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
My SQL Query is:

select Q1.paAmount, Q2.pAmount
From
(select sum(pa.amount) paAmount,pa.BookingID paBookingid from package_acct pa, Groups g , Person_Group pg where ....
group by pa.BookingID
)Q1
Inner Join
(SELECT sum(p.amount) pAmount, p.BookingID pbookingid FROM `payments` p where p.ispaid=1 group by p.BookingID
)Q2
on Q1.paBookingid=Q2.pBookingID

So I'm selecting on results of 2 other selects innerjoin.It works in mysql.

I tried to use createSQLQuery. but it needs entity classes. My select result is 2 BigDecimal values. I couldnt use BigDecimal as entity classes.
What should I do(Im using hibernate 2)?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 2:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use raw jdbc or use hibernate 3

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 2:23 pm 
Regular
Regular

Joined: Wed Sep 22, 2004 8:27 am
Posts: 89
hi.. is it really possible make a criteria o HQL that return a non entity classes?? Can i write a quary that return any field of a table?

Could anyone write examples? Or tell me where i can read this...

thanks


Top
 Profile  
 
 Post subject: Is there any way to change this query to HQL?
PostPosted: Tue Jul 12, 2005 2:53 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
Is there any way to change this query to HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 4:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
foxmarco - yes, read the docs for scalar queries.

sh_sadrai - probably

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 11:55 am 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
I could wite such a query with scalar SQLQuery.But I couldnt find any docs about HQL scalar queries.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 11:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://www.hibernate.org/hib_docs/v3/re ... ing-scalar

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 12:26 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
But It seems in hibernate, scalar queries mean different.
I am looking for queries that I can join two selects like:

select Q1.paAmount, Q2.pAmount
From
(select sum(pa.amount) paAmount,pa.BookingID paBookingid from package_acct pa, Groups g , Person_Group pg where ....
group by pa.BookingID
)Q1
Inner Join
(SELECT sum(p.amount) pAmount, p.BookingID pbookingid FROM `payments` p where p.ispaid=1 group by p.BookingID
)Q2
on Q1.paBookingid=Q2.pBookingID


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 12:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no - what you are doing there is a scalar query (its returning two basic values) and you are utilizing join with sub-queries. Not available in HQL.

just do it in native sql if that works for you.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 12:35 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
I was just concerned about the speed.
But I tried the SQL query. It was pretty faster than HQL!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 12:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh yes ? raw native sql does not return persistent objects it "just" return raw data.... use the right tool for the job, both worlds has merits.

_________________
Max
Don't forget to rate


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