Hi
I have a small tree structure database with inheritance.
I decided to use the "table per subclass mapping strategy" (see mapping below).
In the top level is class TmpC, and it has two subclasses: TmpD, TmpE.
One register in table TmpC has a correspondence with one register in TmpD or with one register in TmpE, but not both.
Then, in my code, I load a TmpC object from its numeric code:
Code:
tmpC = (TmpC) hib_session.load(TmpC.class, new Long(cod));
and Hibernate translates this load into this select:
Code:
SELECT tmpc0.cod AS cod,
CASE
WHEN tmpc0_1.cod IS NOT NULL THEN 1
WHEN tmpc0_2.cod IS NOT NULL THEN 2
WHEN tmpc0.cod IS NOT NULL THEN 0
END
AS clazz_,
tmpc0.nombre AS nombre220_, tmpc0_1.descripcion AS descripcion221_,
tmpc0_2.descripcion AS descripcion222_
FROM tmp_c tmpc0, tmp_d tmpc0_1, tmp_e tmpc0_2
WHERE tmpc0.cod = ?
AND tmpc0.cod = tmpc0_1.cod(+)
AND tmpc0.cod = tmpc0_2.cod(+)
That is, Hibernate does an outer-join to build the result.
But I want NOT to do this outer-join. I want to disable it, and if I query for an object of TmpC type, I want the general object TmpC, not an instance of type TmpD or TmpE. Because I don't care attributes of TmpD, TmpE.
I want something like:
Code:
SELECT tmpc0.cod AS cod,
tmpc0.nombre AS nombre
FROM tmp_c tmpc0
WHERE tmpc0.cod = ?
Is there any way to avoid that outer-join?
Thanks a lot.
----
Hibernate version: 1.2 and 2.1.8 (is the same)
Mapping document:
Code:
<class
name="com.exis.pullmantur.sgt.dataaccess.TmpC"
table="TMP_C"
polymorphism="implicit"
>
<id
name="cod"
type="java.lang.Long"
column="COD"
unsaved-value="any"
>
<generator class="assigned"/>
</id>
<property
name="nombre"
type="java.lang.String"
column="NOMBRE"
not-null="true"
length="100"
/>
<joined-subclass
name="com.exis.pullmantur.sgt.dataaccess.TmpD"
table="TMP_D">
<key column="COD"/>
<property
name="descripcion"
type="java.lang.String"
column="DESCRIPCION"
not-null="true"
length="100"
/>
</joined-subclass>
<joined-subclass
name="com.exis.pullmantur.sgt.dataaccess.TmpE"
table="TMP_E">
<key column="COD"/>
<property
name="descripcion"
type="java.lang.String"
column="DESCRIPCION"
not-null="true"
length="100"
/>
</joined-subclass>
</class>