-->
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.  [ 2 posts ] 
Author Message
 Post subject: <union-subclass> 'where' clause problem
PostPosted: Tue Apr 10, 2007 5:25 pm 
Newbie

Joined: Tue Apr 10, 2007 5:00 pm
Posts: 1
I started using <union-subclass>, mainly for polymoriphic associations.
I spotted some performance issue with selecting top level abstract objects by 'where' clause.
Imagine AbstractAB and two concrete subclasses ConcreteA and ConcreteB. While getting AbstractAB
by id hibernate issues something like:
select a.* (select * from ConcreteA union select * from ConcreteB) as a where a.id = ?.
And here is the problem. Why 'where'clause is not issued for each union selects but for whole combined result? it's not really efficient.
I tried to work that around and write my <loader query. I did have a problems though with sql and aliases.

Let's have simplified:

<class name="AbstractAB" abstract="true">
<property name="id"/>
<property name="description"/>
<loader query-ref="loadAbstractAB"/>
</class>

<union-subclass name="ConcreteA" extends="AbstractAB">
</union-subclass>

<union-subclass name="ConcreteB" extends="AbstractAB">
</union-subclass>

Here is the problem. Currently it looks like that:

<sql-query name="loadAbstractAB">
<return class="ConcreteA" alias="a"/>
<return class="ConcreteB" alias="b"/>
SELECT {a.*} FROM ConcreteA a WHERE a.id=:id
UNION
SELECT {b.*} FROM ConcreteB b WHERE b.id=:id
</sql>

When I load the AbstractAB I got:

IntegerType:132 - could not read column value from result set: id4_1_; Column 'id4_1_' not found.

Strange thing is that if i copy/paste generated SQL it executes correctly in database !

Does anyone have any clue? And what about that union-subclass 'where' clause, why is applied
to the combined results not partial?


Top
 Profile  
 
 Post subject: Re: <union-subclass> 'where' clause problem
PostPosted: Mon Jun 25, 2012 10:57 am 
Newbie

Joined: Mon Jun 25, 2012 10:52 am
Posts: 2
Hello,

I'm also wondering why the where clause is applied on the combined result and not on the partial queries (same for limit clause which might increase performance in some cases).
Does anyone know how to improve hibernate behaviour ?

Note : I'm using hibernate 3 with union-subclass on a MySQL database. I've tested with hibernate 4 and it seems to behave the same way.

Thanks 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.  [ 2 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.