-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to write the mapping file
PostPosted: Mon Apr 10, 2006 3:01 pm 
Newbie

Joined: Fri Apr 07, 2006 7:16 pm
Posts: 3
I have the following class heirarchy (getter/setter excluded)

class Question {
String text;
}

class Long extends Question {
Integer maxLength;
}

class Short extends Question {
List choices;
}

class ShortWithAnswer extends Short { }

class Choice {
String choiceText;
}

class ChoiceWithAnswer extends Choice {
Boolean correct;
}


Now the list 'choices' will contain Choice objects when the questions type is Short and will contain ChoiceWithAnswer objects when the question type is ShortWithAnswer.

The table structure is as follows:

QUESTION
- qid
- text
- maxLength
- qtype (used as a discriminator)

CHOICE
- qid
- choicetext
- correct

Any help is appreciated. Thanks

Hibernate version:

2.1

Name and version of the database you are using:

Oracle 9i


Top
 Profile  
 
 Post subject: 2 c
PostPosted: Mon Apr 10, 2006 6:32 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I would suggest flattening class hierarchy (just getting rid of all the inheritance), and then the mapping will be trivial.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Re: 2 c
PostPosted: Mon Apr 10, 2006 6:36 pm 
Newbie

Joined: Fri Apr 07, 2006 7:16 pm
Posts: 3
kgignatyev wrote:
I would suggest flattening class hierarchy (just getting rid of all the inheritance), and then the mapping will be trivial.


yes but I have actually posted a simplyfied version of an existing program that I am supporting. I have added to the heirarchy and just need some help updating the mapping file. Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 6:51 pm 
Newbie

Joined: Fri Apr 07, 2006 7:16 pm
Posts: 3
Here is my attempt. The error I get is "Found shared references to a collection: Short.choices" at run time. I basically need some way to override the definition of the List choices.



Code:
<hibernate-mapping>
  <class name="Question" table="QUESTION" discriminator-value="null"
      dynamic-update="true" polymorphism="explicit">

  <!-- Discriminator -->
  <discriminator column="QUESTION_TYPE" type="character" not-null="true"/>
 
  <!-- Base class -->
  <property name="text" column="LONG_TEXT" not-null="true"/>
      
  <!-- Subclass QuestionLong -->
  <subclass name="Long" discriminator-value="L">
     <property name="maxLength" column="MAX_RESPONSE_LENGTH"/>
  </subclass>

  <!-- Subclass QuestionShort -->
     <subclass name="Short" discriminator-value="S">
   <list name="choices" lazy="false" table="CHOICE" outer-join="true" cascade="all">
            <key>
      <column name="QUESTION_NUMBER"/>
            </key>
                <index column="CHOICE_NUMBER"/>
   <composite-element class="Choice">
          <property name="choiceText" />         </composite-element>
                </list>
         
     <!-- Subclass QuestionWithAnswer -->
     <subclass name="QuestionWithAnswer" discriminator-value="A">
                  <list name="choices" lazy="false" table="CHOICE" outer-join="true" cascade="all">
            <key>
               <column name="QUESTION_NUMBER"/>
            </key>
                <index column="CHOICE_NUMBER"/>
            <composite-element class="ChoiceWithAnswer">
   <property name="choiceText" />               <property name="correct" column="CORRECT"/>
                  
            </composite-element>
         </list>
     </subclass>
               
  </subclass>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Tue Apr 11, 2006 5:05 am 
Newbie

Joined: Tue Apr 11, 2006 4:57 am
Posts: 17
I have exactly the same problem. We have big class hierarchy with multiple level of inheritance, and our mapping strategie will be with Table per subclass (<joined-subclass>).

How to create a mapping file?

this is probabbly a stupid question, but is this possible?
<joined-subclass>
<key ...>
<property...>
<joined-subclass>
<key ...>
<property...>
</joined-subclass>.
</joined-subclass>.


It may describe 3 level of inheritance.

This is very important guys, I need help asap !


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