You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Saleem Shafi <sa...@gmail.com> on 2004/08/25 17:39:04 UTC

inheritance with multiple joined tables

Someone asked about this earlier (about a year ago), but didn't get a
response, so i thought i'd try again..

I'm trying to use option #3 for inheritance mapping, meaning i've got
1 table for my base class, and a separate table for my sub-class..  In
order to hydrate an instance of the sub-class, a joined would be
needed between the two..  If i query against the sub-class, everything
is fine; however, if i query for the same ID (the ids in both tables
are the same) against the base class, an instance of the base class is
created instead of the subclass that that row really represents.

Is there any way to query against the base class and get instances of
the subclass returned using this configuration?  It seems to me that i
would need to identify the subclass that the base class row represents
(i.e. objConcreteClass), but the docs don't mention it and the
implementation won't join the tables beforehand anyway..  Little help?


Saleem.

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: inheritance with multiple joined tables

Posted by David Courtin <dc...@systemplus.fr>.
Hello

I've done something like this while implementing an ACL system in OJB. 
Here is a part of my repository_user.xml.
When I request for an collection of java.security.Principal I get both 
User an Group.

Hope this help. Bye

David

<!-- Definitions for interface java.security.Principal -->
   <class-descriptor class="java.security.Principal">
        <!-- Never put PrincipalImpl in the list,
                this is just an fake class that is used to set up an 
unique index between
                the other to class -->
      <extent-class class-ref="systemplus.acl.AclGroup" />
      <extent-class class-ref="systemplus.account.UserOfAccount" />
   </class-descriptor>
  
<!-- Definitions for systemplus.acl.PrincipalImpl -->
  <class-descriptor
      class="systemplus.acl.PrincipalImpl"
      table="ACL_PRINCIPALS"
   >
  
      <field-descriptor
         name="id"
         column="ID"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"
      />
   
  </class-descriptor>
 
  
<!-- Definitions of systemplus.acl.AclGroup -->
  <class-descriptor
      class="systemplus.acl.AclGroup"
      table="ACL_GROUP"
   >
  
   <reference-descriptor name="super"
        class-ref="systemplus.acl.PrincipalImpl"
        auto-retrieve="true"
        auto-update="true"
        auto-delete="true"
    >
        <foreignkey field-ref="id"/>
    </reference-descriptor>
    
     <field-descriptor
         name="id"
         column="ID"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"
      />
      <field-descriptor
         name="parentGroup"
         column="ID_PARENT"
         jdbc-type="INTEGER"
      />
      <field-descriptor
         name="name"
         column="GROUP_NAME"
         jdbc-type="VARCHAR"
      />
      <collection-descriptor
         name="principals"
         
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
         element-class-ref="java.security.Principal"
         auto-retrieve="true"
         auto-update="link"
         indirection-table="ACL_PRINCIPALS_GROUP"
      >
         <fk-pointing-to-element-class column="CHILD_ID"/>
         <fk-pointing-to-this-class column="GROUP_ID"/>
      </collection-descriptor>
  </class-descriptor>
    
<!-- Definitions of systemplus.account.UserOfAccount -->
  <class-descriptor
      class="systemplus.account.UserOfAccount"
      table="USER_OF_ACCOUNT"
     
   >
  
   <reference-descriptor name="super"
        class-ref="systemplus.acl.PrincipalImpl"
        auto-retrieve="true"
        auto-update="true"
        auto-delete="true"
    >
        <foreignkey field-ref="id"/>
    </reference-descriptor>
     <reference-descriptor
       name="account"
       class-ref="systemplus.account.Account"
       auto-retrieve="true"
       auto-update="false"
       auto-delete="false"
      >
          <foreignkey field-ref="accountAccountId"/>
     </reference-descriptor>
      <field-descriptor
         name="name"
         column="USER_LOGIN"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="id"
         column="ID"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"
      />
      <field-descriptor
         name="mainUser"
         column="MAIN_USER"
         jdbc-type="INTEGER"
         
conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
      />
      <field-descriptor
         name="pass"
         column="PASS"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="firstName"
         column="FIRST_NAME"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="lastName"
         column="LAST_NAME"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="company"
         column="COMPANY"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="businessPhone"
         column="BUSINESS_PHONE"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="address1"
         column="ADDRESS1"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="address2"
         column="ADDRESS2"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="city"
         column="CITY"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="state"
         column="STATE"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="postalCode"
         column="POSTAL_CODE"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="country"
         column="COUNTRY"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="languagePref"
         column="LANGUAGE"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="jobRole"
         column="JOB_ROLE"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="companyProfile"
         column="COMPANY_PROFILE"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="jobTitle"
         column="JOB_TITLE"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="email"
         column="EMAIL"
         jdbc-type="VARCHAR"

      />
      <field-descriptor
         name="accountAccountId"
         column="ACCOUNT_ACCOUNT_ID"
         jdbc-type="INTEGER"
      />
      <collection-descriptor
         name="principals"
         
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
         element-class-ref="systemplus.acl.AclGroup"
         auto-retrieve="true"
         auto-update="link"
         indirection-table="ACL_PRINCIPALS_GROUP"
      >
         <fk-pointing-to-this-class column="CHILD_ID"/>
         <fk-pointing-to-element-class column="GROUP_ID"/>
      </collection-descriptor>

  </class-descriptor>

Saleem Shafi a écrit :

>Someone asked about this earlier (about a year ago), but didn't get a
>response, so i thought i'd try again..
>
>I'm trying to use option #3 for inheritance mapping, meaning i've got
>1 table for my base class, and a separate table for my sub-class..  In
>order to hydrate an instance of the sub-class, a joined would be
>needed between the two..  If i query against the sub-class, everything
>is fine; however, if i query for the same ID (the ids in both tables
>are the same) against the base class, an instance of the base class is
>created instead of the subclass that that row really represents.
>
>Is there any way to query against the base class and get instances of
>the subclass returned using this configuration?  It seems to me that i
>would need to identify the subclass that the base class row represents
>(i.e. objConcreteClass), but the docs don't mention it and the
>implementation won't join the tables beforehand anyway..  Little help?
>
>
>Saleem.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>  
>

-- 

David Courtin
President & CEO

System Plus S.A.S
9, rue Alfred Kastler
44307 Nantes Cedex 03
France
Tel : (33) 2 40 25 21 74
email : dcourtin@systemplus.fr
 <ma...@systemplus.fr>www.systemplus.fr <http://www.systemplus.fr> - Microelectronic Consulting and Software


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org