-->
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.  [ 3 posts ] 
Author Message
 Post subject: Subclassing without discriminators (rather joins)
PostPosted: Wed Feb 01, 2006 6:17 am 
Beginner
Beginner

Joined: Sun Oct 09, 2005 3:21 pm
Posts: 40
Hibernate version: 3.1.1

Mapping documents:
Code:
<class name="Resurs" table="RESURS">

   <id name="id">
      <column name="RESURSID" sql-type="INTEGER"/>
      <generator class="identity">
      </generator>
   </id>

   ....(more)

                <set name="resurs1Relationer" lazy="true" inverse="true" cascade="save-update" where="TOMTSTAMP is null">
      <key column="RESURSID1" on-delete="noaction" not-null="true"/>
      <one-to-many class="ResursRelation"/>
   </set>

                ....(more)
</class>

<class name="ResursRelation" table="RESURSRELATION">

   <id name="id">
      <column name="RESRELID" sql-type="INTEGER"/>
      <generator class="identity">
      </generator>
   </id>

   <many-to-one lazy="false" name="resurs1" class="Resurs" foreign-key="FK_RESREL_RES1" index="RESURSRELATION_FK">
      <column name="RESURSID1" sql-type="INTEGER"/>
         </many-to-one>

   <many-to-one lazy="false" name="resurs2" class="Resurs" foreign-key="FK_RESREL_RES2" index="RESURSRELATION_FK">
      <column name="RESURSID2" sql-type="INTEGER"/>
   </many-to-one>

   <many-to-one lazy="false" name="typ" class="ResursRelationtyp" foreign-key="FK_RESRELT_RESREL" index="RESURSRELATION_FK">
      <column name="RESRELTYPID" sql-type="INTEGER"/>
   </many-to-one>

                ......(more)

</class>

<class name="ResursRelationtyp" table="RESURSRELATIONTYP">

   <cache usage="read-only"/>

   <id name="id">
      <column name="RESRELTYPID" sql-type="INTEGER"/>
      <generator class="identity">
      </generator>
   </id>

   <property name="beteckning">
      <column name="BETECKNING" length="50" not-null="true"/>
   </property>

                .....(more)

</class>



Name and version of the database you are using: DB2 V8.2

[b]Problem: [b]
Want to subclass the ResursRelation based on the RESRELTYPID column without using a discriminator relying on a subselect to the ResursRelationtyp class (associated through the RESRELTYPID column). Would like to use a join somehow rather than a pure discriminator since with DB2 does not allow subselects a conditions of inner joins (ie. will happen when I start searching after Resurs objects connected to ResursRelation - see set definition - and want a particular subclass of the ResursRelation class based on ResursRelationtyp). Is there any inheritance model usable via Hiberante? Ideas?


Top
 Profile  
 
 Post subject: Simplifying my question
PostPosted: Wed Feb 01, 2006 5:24 pm 
Beginner
Beginner

Joined: Sun Oct 09, 2005 3:21 pm
Posts: 40
Maybe I should lighten my original question. Say you have two tables:
1) a table holding resource objects (discernable by type)
2) another table containing all of the resource types

One way to subclass the resource table is by using a discriminator that ties the foreign key relationship to a string value that each subclass may use (i.e. textual replacement for the natural index - numeric sequence generated by a database that isn't too transferrable between database instances making a name column more reasonable).

What I am looking for is a way to subclass via a join of the two tables (with a where clause on the name of the type of resource) but still mapping my subclass to the resource table.

Any ideas?


Top
 Profile  
 
 Post subject: Maybe subselect (ie.view) with sql-insert/sql-update
PostPosted: Wed Feb 15, 2006 6:06 pm 
Beginner
Beginner

Joined: Sun Oct 09, 2005 3:21 pm
Posts: 40
Still wondering if my original problem can be solved...

What if I made a class similar to ResursRelation:

Code:
<class name="ResRelSubQuery" mutable="false">
  <subselect>
    select t1.c1,t1.c2,t1.c3 .....
    from resursrelation t1, resurs t2, resurstyp t3
    where t1.resursid1=t2.resursid
    and t1.tomtstamp is null
    and t2.resurstypid=t3.resurstypid
    and t3.beteckning='version'
  </subselect>
  <id name="c1"/>
  <property name="c2" ..../>
   ....

  <sql-insert>
     insert into resursrelation (c2,c3,...) values (?,?,...)
  </sql-insert>
  ....
</class>


So that the ResRelSubQuery is really a view of the ResursRelation table (ie. immutable) but inserts/updates may occur via the sql-insert/sql-update tags. Is something like this possible. Or will the subselect force the class to be truely read-only (ie. no inserts/updates allowed).

If I had a ResRelSubQuery class like the above then I could map a set from the Resurs subclasses to permutations of the ResRelSubQuery class and solve the original problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.