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: Hibernate and complex oracle SQL queries
PostPosted: Mon May 10, 2004 8:21 am 
Newbie

Joined: Mon May 10, 2004 8:16 am
Posts: 6
Hi all

I would like to do the following oracle sql query with hibernate by using
session.createSQLQuery but I don't know how...

SELECT fabId, produitId, SUM(total) AS total FROM
(
SELECT p.fab_id AS fabId, p.produit_id AS produitId,
SUM(p.penalite_Valeur) AS total
FROM PFT_PENALITE p
GROUP BY p.fab_id, p.produit_id

UNION

SELECT f.fab_id AS fabId, f.produit_id AS produitId,
SUM(f.fiche_Penalite)
FROM PFT_FICHE f
WHERE f.fiche_penalite >0
GROUP BY f.fab_id, f.produit_id
)
GROUP BY fabId, produitId


Is it possible to do that ?
what to do with the alias parameter ?

thanks a lot for your help...

BTW: if someone sees another simplier way to do a union on 2 queries
followed by a group by, the solution is welcome....


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

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
union is not allowed. Try to think in object rather than in relational model when doing your query.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: thanks
PostPosted: Mon May 10, 2004 12:35 pm 
Newbie

Joined: Mon May 10, 2004 8:16 am
Posts: 6
I solved my problem by using a view.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 12:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hehe this works too ;-)

_________________
Emmanuel


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.