-->
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: Workaround for Subselects in From Clause
PostPosted: Fri Jan 14, 2011 3:28 am 
Newbie

Joined: Fri Jan 14, 2011 3:10 am
Posts: 1
Hello to all of you.

I am quite new to hibernate, but i am really exited about the functionallity, and the easy usage.
However i am creating an application where i have to perform a subselect in a from clause.
After searching the hibernate reference i found out, that hibernate does not support subselects in from clause.
Quote:
Note that HQL subqueries can occur only in the select or where clauses.


My question: is there any workaround to get such a select?
I am providing an example:
I Have a table which stores dates for member. But for a statistic, i am only interessted in the in the amount of dates per month(and year). But due to the fact that one member hase more entries in the table, i am only interrested in the latest date per member.
In normal sql i would wrote this (pseudo sql)
Code:
SELECT Count(member), Month(date), Year(date)
FROM (
          SELECT user as member, max(time) as date
          FROM table
          WHERE ....
          GROUP BY user
         ) AS vtable
GROUP BY Month(date), Year(date)
ORDER BY ...


This code is working in sql. I testet it directly in the database. Unfortunately i cant think of another way to get this statement provided.
I can do the Subselect and create a new object, where i count the members in the java code. But the application provices about 4000 members with each 50 relevant entries. And i dont like to select 4000 rows from the database, just to work with about 30 sets of data.

Is there any posibillity?

Or only the words of Chris Wilson:
Quote:
I just haven't needed it yet, so I haven't had a reason to implement it.


Thank you for your help


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.