| Author |
Hibernate - Using subclass and joined-subclass element
|
Osama Shakeel
Greenhorn
Joined: Sep 16, 2003
Posts: 1
|
|
Hi, Im having a problem with using <subclass> and <joined-subclass>. I have a base class Question (mapped onto table: Question) from which 2 classes extend namely, EssayQuestion and MCQ. I have mapped MCQ onto the same table: Question. Thus I have used <subclass> for MCQ mapping. For this I have specified a discriminator column in Question table and discriminator values in both Question and MCQ mappings. I have mapped EssayQuestion onto a different table: EssayQuestion using the <joined-subclass> element. But in this case I have not specified any discriminator values. So my complete mapping is of the form: <class name="Question" table="Question" discriminator-value="0" > <id name="id" column="id"> <generator class="identity"/> </id> <discriminator column="type" type="integer"/> <subclass name="MCQ" discriminator-value="1"> ...... </subclass> <joined-subclass name="EssayQuestion" table="EssayQuestion" > <key column="QuestionId_FK"/> <property name="minWords" column="MinWords"/> <property name="notes" column="Note"/> </joined-subclass> </class> But when I build the session factory I get the following exception: Hibernate Exception = net.sf.hibernate.MappingException: Error parsing discriminator value: For input string: "EssayQuestion" I have some questions regarding the whole scenario: Is it because since I have specified a discriminator value in the base class Hibernate expects a discriminator value be provided for EssayQuestion even if it is specified in <joined-subclass> element? Is it that if a class is mapped using table-per-class mapping all of its subclasses will be mapped that way with no possibility of its subclass to be mapped using table-per-subclass mapping? The same question as above but the mapping is table-per-subclass? Isnt there anyway I can map 2 subclasses of a class using "table-per-class" with one and "table-per-subclass" with the other? Am I missing something here? Thanx in advance for any advice and suggestions
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
While I am a strong supporter of Javaranch, I don't feel we, as a community, would be giving you the best service we could if we were to deny you something that can really help with your problem. What I mean is, I would suspect that there are very few Hibernate experts that hang out on these forums, and I think you would get a better answer to your question faster if you were to ask it on the Hibernate Forums.
|
 |
Buster Keaton
Greenhorn
Joined: Aug 16, 2004
Posts: 1
|
|
It's in the Hibernate documentation, chapter 8 : "Hibernate does not support mixing <subclass> mappings and <joined-subclass> mappings inside the same <class> element."
|
 |
 |
|
|
subject: Hibernate - Using subclass and joined-subclass element
|
|
|