-->
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: Discriminator is not used in sql when using subselect fetch
PostPosted: Wed Oct 05, 2005 8:42 pm 
Beginner
Beginner

Joined: Tue Aug 23, 2005 3:52 pm
Posts: 26
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Hello,

I am using the bellow mentioned configuration file to execute following HQL. However the sql that Hibernate produces is not what I would expect. If you look at the sql to retrieve one-to-many collections (settlement instructions and desk) discriminator is used to establish join but it is not being used to limit collection items. Since this is a one-to-many relationship establishing a join is not enough, a discriminator has to be applied to collection too (entity >=0). Please let me know if this is a bug, or I am doing something wrong.



Thanks
Leonid


Mapping documents:

Code:
<class table="brokers" name="Counterparty" mutable="false">
     <id name="code" type="integer" column="broker_code"/>   
   <set name="desks" fetch="subselect" lazy="false">
      <key column="broker_code"/>
      <one-to-many class="Desk"/>         
   </set>   
   <set name="settlementInstructions" fetch="subselect" lazy="false">
      <key column="broker_code"/>
      <one-to-many class="SettlementInstruction"/>
   </set>
</class>

<class table="sub_brokers" name="Desk" mutable="false">
    <composite-id name="id"  class="Desk$Id">
        <key-property name="brokerCode" type="integer" column="broker_code"/>
   <key-property name="subBrokerCode" type="string" column="sub_broker_code"/>
     </composite-id>   
     <property name="entity" type="integer" column="entity"/>
</class>

<class table="broker_routing" name="SettlementInstruction" mutable="false">    
   <id name="settleCode" type="integer" column="settle_code"/>       
   <property name="brokerCode" type="integer" column="broker_code"/>
   <property name="entity" type="integer" column="entity"/>
  </class>



HQL

select distinct b from Counterparty b join b.desks d left join b.settlementInstructions s where d.entity >= 0 and s.entity >= 0


The generated SQL:

Code:
select distinct counterpar0_.broker_code as broker1_
from externdb.dbo.brokers counterpar0_
inner join externdb.dbo.sub_brokers desks1_ on counterpar0_.broker_code=desks1_.broker_code
left outer join externdb.dbo.broker_routing settlement2_ on counterpar0_.broker_code=settlement2_.broker_code
where desks1_.entity>=0 and settlement2_.entity>=0


Code:
select settlement0_.broker_code as broker2_1_, settlement0_.settle_code as settle1_1_,
       settlement0_.settle_code as settle1_0_, settlement0_.broker_code as broker2_2_0_,
       settlement0_.entity as entity2_0_
from externdb.dbo.broker_routing settlement0_
where settlement0_.broker_code in (select counterpar0_.broker_code
                                   from externdb.dbo.brokers counterpar0_
                                   inner join externdb.dbo.sub_brokers desks1_ on counterpar0_.broker_code=desks1_.broker_code
                                   left outer join externdb.dbo.broker_routing settlement2_ on counterpar0_.broker_code=settlement2_.broker_code
                                   where desks1_.entity>=0 and settlement2_.entity>=0)
(expected "and settlement0_.entity>=0)

Code:
select desks0_.broker_code as broker1_1_, desks0_.sub_broker_code as sub2_1_, desks0_.broker_code as broker1_0_,
        desks0_.sub_broker_code as sub2_0_, desks0_.entity as entity1_0_
from externdb.dbo.sub_brokers desks0_
where desks0_.broker_code in (select counterpar0_.broker_code
                              from externdb.dbo.brokers counterpar0_
                              inner join externdb.dbo.sub_brokers desks1_ on counterpar0_.broker_code=desks1_.broker_code
                              left outer join externdb.dbo.broker_routing settlement2_ on counterpar0_.broker_code=settlement2_.broker_code
                              where desks1_.entity>=0 and settlement2_.entity>=0)
(expected "and desk0_.entity>=0)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 05, 2005 11:52 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Why would Hibernate use an arbitrary property as a discriminator? You don't have a real discriminator anywhere in your mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 05, 2005 11:53 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Btw, your mapping is broken. Read the "parent/child" chapter in the reference documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 8:46 am 
Beginner
Beginner

Joined: Tue Aug 23, 2005 3:52 pm
Posts: 26
christian wrote:
Why would Hibernate use an arbitrary property as a discriminator? You don't have a real discriminator anywhere in your mapping.


When I use word "discriminator" I refer to the sql discriminator. I don’t want to specify a where clause in the collection mapping, however I do need to use HQL to limit the collection item that are return when I use subselect fetch mode. Can you please point me to right direction.

Also you mentioned that there is something wrong with my mapping, can you please be more descriptive. I looked over that chapter that you mentioned and I didn't find any problems.

Thanks.

Leonid


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.