-->
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: subquery von sql nach hql
PostPosted: Mon Jan 26, 2009 9:33 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
Hallo,


In SQL hab ich sowas:

Code:
select *
from (select max(item), max(item1) from Table1)
union
(select max(item), max(item1) from Table2)



Wie kann ich dasselbe in HQL ausdrücken?

Hab es mit folgendem HQL versucht, geht leider nicht:

Code:
from (select max(t1.item), max(t2.item1) from Table1 t1) 
union 
(select max(t2.item), max(t2.item1) from Table2 t2)



Vorschläge?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 4:26 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
Hibernate unterstützt keine Unions..

hmm..jedoch subselects,

wenn ich nur sowas umsetzen will:

SQL:

Code:
select *
from (select max(item), max(item1) from Table1)


dieses HQL funzt nicht:

Code:
from (select max(t1.item), max(t2.item1) from Table1 t1)


kennt einer die syntax?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 4:41 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Meines Wissens nach sind in der from-clause in HQL keine subselects sondern nur Entity-Namen erlaubt. Ich denke, du musst bei einer SQLQuery bleiben.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 7:03 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
schade das sowas nicht geht:

select (select max(t1.item), max(t2.item1) from Table1 t1)

und in der Hibernate-Referenz (14.13. Subqueries) steht sowas drinnen, was möglich ist:

Quote:
select cat.id, (select max(kit.weight) from cat.kitten kit)
from Cat as cat


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.