java - Implementing multiple JOINS in HQL -


i'm trying implement hql query. i've been able implement in sql - i'm little more familiar with. keep getting hung on inner joins.

the classes implemented this...

class item  class component extends item     private item parentitem;  class assembly extends item  

so far, have hql...

select item.blah, comp.blah, assembly.blah component comp left outer join comp.parentitem item, assembly assembly  item.parentitem = assembly 

this works - except need last 3 lines left outer join rather mutually exclusive condition. i've tried implement in number of ways - keep running mapping problems.

<hibernate-mapping>     <class lazy="false" name="com.kcp.common.domain.inventory.item"    table="w_inv_inv_item" where="deleted=0">         <joined-subclass lazy="false" name="com.kcp.common.domain.inventory.component" table="w_inv_inv_component">          <key>            <column name="id">                <comment>primary , foreign key w_inv_inv_item.</comment>             </column>          </key>          <many-to-one cascade="all" class="com.kcp.common.domain.inventory.item" name="parentitem" outer-join="true">               <column name="parent_item_id">                 <comment>foreign key identifying item component assembled.</comment>               </column>          </many-to-one>        </joined-subclass>          <joined-subclass lazy="false" name="com.kcp.common.domain.inventory.assembly" table="w_inv_inv_major_assembly">              <key>             <column name="id">               <comment>primary , foreign key w_inv_inv_item.</comment>             </column>           </key>     </class>  </hibernate-mapping> 

also - got work in sql so...

from dbo.w_inv_inv_item item inner join dbo.w_inv_inv_component comp on item.id = comp.id left outer join dbo.w_inv_inv_item parentinv on comp.parent_item_id = parentinv.id left outer join dbo.w_inv_inv_major_assembly parentma on comp.parent_item_id = parentma.id 

if include left join condition in clause, act inner join.

if item optional, item.parentitem has optional too, need include in left join.

that hql query generate horrible sql query , should optimize anyway.

try this:

select     i.blah,     c.blah component c left join c.parentitem left join i.parentitem p      p null or p.class = 'assembly'    class item  class component extends item     private item parentitem;  class assembly extends item      

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -