[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4456) Hibernate gives a Javaassist object rather than the real object that I need in a subclass mapping

Ken Egervari (JIRA) noreply at atlassian.com
Wed Sep 23 06:35:50 EDT 2009


Hibernate gives a Javaassist object rather than the real object that I need in a subclass mapping
-------------------------------------------------------------------------------------------------

                 Key: HHH-4456
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4456
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.3.1
         Environment: 3.3.1 ga, hsqldb/mysql
            Reporter: Ken Egervari


I have an interesting mapping where the parent class is sub classed and is mapped as such... and it contains an object that is also sub classed. Because java doesn't have multiple inheritance, I do this to avoid a wacky exponentially complex inheritance hierarchy. I would say this is pretty normal domain architecture for the type of problem.

Now, on the inner object, Hibernate is doing the mapping just fine, but when I pull it from the database and cast it, it throws an example.

{code}
java.lang.ClassCastException: jawbs.domain.application.questiontype.QuestionType_$$_javassist_7 cannot be cast to jawbs.domain.application.questiontype.MultipleChoiceType
	at jawbs.dao.QuestionDaoTest.findJobApplicationQuestion(QuestionDaoTest.java:122)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
...
{code}

The code is just a test case:
{code}
	@Test
	public void findJobApplicationQuestion() {
		JobApplicationQuestion question = ( JobApplicationQuestion )
			questionDao.find( 2 );

// THIS IS WHERE THE PROGRAM BOMBS

		MultipleChoiceType type = ( MultipleChoiceType ) question.getType();

		assertEquals( "What is the namespace for jawbs in JS?", question.getText() );
		assertEquals( 1, question.getJob().getId() );
		assertEquals( 3, type.getCorrectOption().getId() );
	}
{code}

And the mapping is as follows. There are two entities, one containing another... and both entities are being sub classed.

{code?xml}
    <class name="jawbs.domain.application.Question" table="question" abstract="true">
        <id name="id" column="question_id" type="long">
            <generator class="native"/>
        </id>
        <discriminator column="application_type" type="string"/>
        <property name="text" type="text" />
        <many-to-one name="type" class="jawbs.domain.application.questiontype.QuestionType"
                     column="question_type_id" />

        <subclass name="jawbs.domain.application.JobApplicationQuestion" discriminator-value="JOB">
            <many-to-one name="job" class="jawbs.domain.job.Job"
                         column="job_id"/>
        </subclass>

        <subclass name="jawbs.domain.application.ScholarshipApplicationQuestion" discriminator-value="SCHOLARSHIP">
            <many-to-one name="employer" class="jawbs.domain.employer.Employer"
                         column="employer_id"/>
        </subclass>
    </class>

    <class name="jawbs.domain.application.questiontype.QuestionType" table="question_type" abstract="true">
        <id name="id" column="question_type_id" type="long">
            <generator class="native"/>
        </id>
        <discriminator column="type" type="string"/>
        <many-to-one name="question" class="jawbs.domain.application.Question"
                     column="question_id"/>

        <subclass name="jawbs.domain.application.questiontype.TrueFalseType" discriminator-value="TRUE_FALSE">
            <property name="correctChoice" column="correct_choice" />
        </subclass>

        <subclass name="jawbs.domain.application.questiontype.MultipleChoiceType" discriminator-value="MULTIPLE_CHOICE">
            <many-to-one name="correctOption" class="jawbs.domain.application.questiontype.MultipleChoiceOption"
                         column="correct_option_id"/>
        </subclass>

        <subclass name="jawbs.domain.application.questiontype.OpenEndedType" discriminator-value="OPEN_ENDED">

        </subclass>
    </class>
{code}

I'd appreciate any assistance. I suspect this is a bug, or maybe I configured it wrong. The documentation doesn't really include examples like this, so I dunno what to do to fix it.

Thanks

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list