-->
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.  [ 6 posts ] 
Author Message
 Post subject: Union in HQL - alternatives
PostPosted: Mon May 31, 2004 6:44 am 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
I want to sum all incomes and outcomes (simplified problem). In ordinary SQL I would use UNION, but HQL doesn't support it. I fount the following alternatives:
1) using ordinary SQL query,
2) manually sum incomes and outcomes in java :-(
3) write super class of income and outcome class :-(

Did I miss any alternative? Why HQL doesn't support union? Is it going to?

Another similar question: If I update data via createSQLQuery(), is second level cache synchronized?

Thank you for your help!

Marko


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 12:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I have not yet heard of a reasonable usecase for this. Your usecase is NOT reasonable, since it is not very OO. You get back a list of incomes and outcomes, which do not seem to share a baseclass or interface, and hence cannot be handled polymorphically.

(Hibernate3 has union-subclass, which uses a union to implement polymorphic queries, but that assumes the existence of a base class or interface.)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 2:54 pm 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
Thank you, Gavin, for your help and time.

I am begging for another answer: If I update data via createSQLQuery(), is second level cache synchronized (updated)?

Marko


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can't update via createSQLQuery.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 3:22 pm 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
Thanks.

Marko


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 3:14 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Quote:
I want to sum all incomes and outcomes (simplified problem). In ordinary SQL I would use UNION, but HQL doesn't support it.

Set operations are usefull, but not in this case, store things like "incomes" and "outcomes" in the same table:

Code:
| account | income   | outcome |

If you can not change DB then use View.


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