-->
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: Using Left outer join with defining the corresponding relati
PostPosted: Wed Feb 07, 2007 5:54 am 
Newbie

Joined: Wed Feb 07, 2007 5:27 am
Posts: 1
Query: Can we use the Hibernate's "LEFT OUTER JOIN" in a HQL without defining the corresponding relationship in the hibernate mapping file.

e.g I have 2 hbm files Test.hbm.xml and Child.hbm.xml

Mapping documents:

[b]Snippet from Test.hbm.xml

<hibernate-mapping>
<class
name="Test"
table="Test"
>
<id
name="id"
type="java.math.BigDecimal"
column="ID"
>
<generator class="assigned" />
</id>

<property
name="status"
type="java.lang.String"
column="STAT_C"
not-null="true"
length="30"
/>
</class>
</hibernate-mapping>

Snippet from Child.hbm.xml
<hibernate-mapping>
<class
name="Child"
table="Child"
>
<id
name="childId"
type="java.math.BigDecimal"
column="child_id"
>
<generator class="assigned" />
</id>

<property
name="value"
type="java.lang.String"
column="VAL_C"
not-null="true"
length="30"
/>
</class>
</hibernate-mapping>

Can I write a HQL so as to fetch all the data from Test & Child with join key as Test.id and Child.childId. I want to fetch data from test if Child table doesn't have the corresponding matching row(thus need outer join)

I have tried this:
SELECT test.id FROM Test test left outer join Child child ON test.id = child.childId;
and it doesn't work saying ON is not allowed. I have tried WITH also instead of ON and that also doesn't work.


The SQL equivalent I want to achive is : select test.id from Test test, Child child where test.id = child.childId(+);

Can I do the same through HQL with the hibernate files given above. Please note that I can not define the relationship between these 2 tables due to some of my specific business restrictions.

If hibernate doesn't allow this without relationship then what are the possible alternativesI have. I guess one possible alternative may be write the SQL statment instead of HQL. Is there any other solution to this.

Name and version of the database you are using:

Oracle10g


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.