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
|
|