wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate - Using subclass and joined-subclass element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate - Using subclass and joined-subclass element" Watch "Hibernate - Using subclass and joined-subclass element" New topic

Hibernate - Using subclass and joined-subclass element

Osama Shakeel

Joined: Sep 16, 2003
Posts: 1
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"
<id name="id" column="id">
<generator class="identity"/>
<discriminator column="type" type="integer"/>
<subclass name="MCQ" discriminator-value="1">
<joined-subclass name="EssayQuestion"
<key column="QuestionId_FK"/>
<property name="minWords" column="MinWords"/>
<property name="notes" column="Note"/>
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

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.

GenRocket - Experts at Building Test Data
Buster Keaton

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."
I agree. Here's the link: http://aspose.com/file-tools
subject: Hibernate - Using subclass and joined-subclass element