-->
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: HQL to tranparently use join criteria in mapping file
PostPosted: Wed Aug 17, 2005 4:53 pm 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
Hibernate version:3.05

Is there a way for me to execute an HQL query and have the fetch attibute specified for an association in the mapping file be picked up without me having to explicitly specify left outer join in my HQL query?

It seems like the fetch attibute of a many-to-one association is used only when loading the entity directly but not when an HQL is run where the join is implicit.

Consider the mapping below where the fetch type is outer join:

Mapping documents:
Code:
   <class name="foo.Lane" table="lane">
      <id name="id" column="lane_id" type="long" unsaved-value="null">
         <generator class="sequence">
            <param name="sequence">lane_sequence</param>
         </generator>
      </id>
...
      <many-to-one name="businessUnit" column="businessunit_id"  fetch="join"     
         class="foo.BusinessUnit" />
   </class>




When I run

Code:
session.load(Lane.class, new Long(1))
the generated SQL does have an outer join with the BusinessUnit table

However when I run

Code:
session.createQuery("from Lane l where l.businessUnit.name is null").list()


the generated SQL does not have the outer join. In the HQL above, the where conditional works correctly only when an outer join is executed.

If I run the following by explicitly adding the join criteria in the HQL, it works.

Code:
session.createQuery("from Lane l left join fetch l.businessUnit where l.businessUnit.name is null").list()


Unfortunaltey I cant use the latter version as I am dynamically building a filter and at the point of execution of the code I only have knowledge of the entity in question (Lane) and the properties as Strings ("businessUnit.name") and the filter value ( null, not null, *foo* etc).


Thanks,
Sanjiv


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.