-->
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.  [ 1 post ] 
Author Message
 Post subject: Fetching colums with max value in a category
PostPosted: Mon Apr 23, 2012 10:11 am 
Newbie

Joined: Mon Apr 23, 2012 9:39 am
Posts: 1
Hi,

I have an entity Calc which has columns serialNo, articleNo, seasonNo and country as category identifier (i.e. all rows with the same value of this columns are members of the same category) and some additional columns. For each category there is a version number column (version=1..n), which differs in categories. To get a resultset that contains the maximum value of each category I am using:

select c.serialNo, c.articleNo, c.seasonNo, c.country, max(version) from Calc c group by c.serialNo, c.articleNo, c.seasonNo, c.country having seasonNo='xxxx'
this is working in native sql and hibernate as well.

Now I want to fetch all columns of my table, which is working in sql like this:
select * from Calc calc inner join (select c.serialNo, c.articleNo, c.seasonNo, c.country, max(version) from Calc c group by c.serialNo, c.articleNo, c.seasonNo, c.country) res
on calc.serialNo=res.serialNo and calc.articleNo=res.articleNo and calc.seasonNo=res.seasonNo and calc.country=res.country

How would I setup the equivalent statement in hibernate. Tried it using hql and criteria without success. Any help appreciated.

regards Uwe


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.