-->
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.  [ 2 posts ] 
Author Message
 Post subject: Inheritance retrieve only superclass object
PostPosted: Mon Mar 14, 2005 12:37 pm 
Newbie

Joined: Wed Mar 09, 2005 8:58 am
Posts: 5
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>


Top
 Profile  
 
 Post subject: your answer is here
PostPosted: Wed Jun 15, 2005 11:54 am 
Newbie

Joined: Wed Jun 15, 2005 11:52 am
Posts: 1
I was also looking for an answer to the same question you asked. I found this post, which seems to provide the solution:

http://forum.hibernate.org/viewtopic.php?t=399


- jonathan.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.