-->
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: Polymorphic in HQL selects
PostPosted: Tue Aug 30, 2005 5:15 am 
Newbie

Joined: Tue Jun 21, 2005 5:23 am
Posts: 8
Hiho

Example: (pseudocode)
class A {String base};
class B extends A {String addon};
Mapped via joined-subclass

Following HQL works:
"select a, a.base, a.addon from A a"

My Problem is, that im not interested into receving all instances of A. I just want a distinct of base + addon.

So i tried something like that:
"select distinct a.base, a.addon from A a"

Hibernate throws no exception, so he thinks that he is able to handle my hql. But my database is not able to work with the resulting SQL, because hib generates faulty wheres (they refer to lacking table aliases).

Is it necessary to include "a" in my resultquery?

Hibernate version: 3.0.5

thx for your Feedback
Bernhard Neuhauser


Top
 Profile  
 
 Post subject: Re: Polymorphic in HQL selects
PostPosted: Tue Aug 30, 2005 8:53 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Cybernd wrote:
Hiho

Example: (pseudocode)
class A {String base};
class B extends A {String addon};
Mapped via joined-subclass

Following HQL works:
"select a, a.base, a.addon from A a"

My Problem is, that im not interested into receving all instances of A. I just want a distinct of base + addon.

So i tried something like that:
"select distinct a.base, a.addon from A a"

Hibernate throws no exception, so he thinks that he is able to handle my hql. But my database is not able to work with the resulting SQL, because hib generates faulty wheres (they refer to lacking table aliases).

Is it necessary to include "a" in my resultquery?

Hibernate version: 3.0.5

thx for your Feedback
Bernhard Neuhauser


What about "from B as b" ? That would give you an object, B, that has two strings "base" and "addon".

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 10:38 am 
Newbie

Joined: Tue Jun 21, 2005 5:23 am
Posts: 8
I know ;o)

But i still want to understand the logic behind hibernate to be able to write more complex queries.

Example:
"select distinct x.a.base, x.a.addon from X x"

My X is a left outer join on another object so it looks more like:
"select distinct x.a.base, x.a.addon from Y y left outer join y.blub.x as x where .. "

So i dont know, how to say ".a" should be from Type B. It seems like hibernate is able to resolve this condition per magic, but only when a will be added to the result.

cybi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 11:20 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Cybernd wrote:
I know ;o)

But i still want to understand the logic behind hibernate to be able to write more complex queries.

Example:
"select distinct x.a.base, x.a.addon from X x"

My X is a left outer join on another object so it looks more like:
"select distinct x.a.base, x.a.addon from Y y left outer join y.blub.x as x where .. "

So i dont know, how to say ".a" should be from Type B. It seems like hibernate is able to resolve this condition per magic, but only when a will be added to the result.

cybi


I can't see anyway you'd be able to do "select distinct x.a.base, x.a.addon from X x" if X's property is an reference to an A Object. Even if the returned object is the subclass B, the reference is an A and you'd have to cast it before you used properties from a B.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


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.