-->
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: GROUP BY and Table per Concrete Class
PostPosted: Tue Jun 13, 2006 12:33 pm 
Newbie

Joined: Tue Jun 13, 2006 12:12 pm
Posts: 3
Hi,
I just wonder if this is the expected behavior or it is a missing Hibernate feature [ or my mistake... :) ]
I have a very simple hierarchy that looks like this:


Code:
public abstract class X {
    private Long OID;
    private Integer xAttr;
    private String status;
   ...
}

public class Y extends X {
    Integer yAttr;
    ...
}

public class Z extends X {
    Integer zAttr;
    ...
}


The hierarchy is mapped with 'Table per Concrete Class' so we have 2 tables: Y and Z.
We are trying to perform a polymorphic query against 'X' class grouping by 'status' attribute (which both concrete classes inherit):

Code:
Query q = session.createQuery(
   "select x.status as STATUS, count(*) as COUNT" +
   " from X x" +
   " group by x.status");
List lst = q.list();


This produces the following queries:

Code:
select z0_.STATUS as col_0_0_, count(*) as col_1_0_ from Z z0_ group by z0_.STATUS

select y0_.STATUS as col_0_0_, count(*) as col_1_0_ from Y y0_ group by y0_.STATUS


The thing is that the grouping is taking place in every table but not in the whole result set.
Is this the expected behavior ? Changing the mapping strategy is not an option for us so we will use a native SQL query as a last resource.

TIA,
Martin


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.