tags:

views:

25

answers:

1

Let's say I have a Question and QuestionHeader class. Question extends QuestionHeader. My mapping looks like this:

<entity class="hr.leads.services.model.jpa.QuestionHeader">
    <table name="question" />
    <inheritance strategy="SINGLE_TABLE" />
    <attributes>
        <basic name="description">
            <column name="description" length="200" nullable="false" />
        </basic>
        <basic name="text">
            <column name="text" length="300" nullable="false" />
        </basic>
        <many-to-one name="band"
            target-entity="hr.leads.services.model.jpa.Band" fetch="EAGER">
            <join-column name="band_id" />
        </many-to-one>
    </attributes>
</entity>

<entity class="hr.leads.services.model.jpa.Question">
    <table name="question" />
    <inheritance strategy="SINGLE_TABLE" />
    <attributes>
        <basic name="visibilityQuestionId">
            <column name="visibility_question_id" nullable="true" />
        </basic>
        <basic name="visibilityQuestionOptionId">
            <column name="visibility_question_option_id"
                nullable="true" />
        </basic>
        <many-to-one name="questionType"
            target-entity="hr.leads.services.model.jpa.QuestionType"
            fetch="EAGER">
            <join-column name="question_type_id" />
        </many-to-one>
        <one-to-many name="options"
            target-entity="hr.leads.services.model.jpa.QuestionOption"
            fetch="EAGER" mapped-by="question">
            <cascade>
                <cascade-all />
            </cascade>
        </one-to-many>
    </attributes>
</entity>

The problem is, when I try to add the entity, here is the SQL that gets generated:

INSERT INTO question (name, display_order, description, text, DTYPE, band_id, visibility_question_id, visibility_question_option_id, question_type_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(String) q1, (int) 1, (String) d1, (String) t, (String) QUESTION, (long) 101, (long) 42, (long) 43, (long) 101]} 

It's putting DTYPE as a column name, and I don't want it to do that! How can I prevent it? I think this is the discriminator value, but I don't want that in my insert statement.

+3  A: 

When using the SINGLE_TABLE strategy the discriminator column is needed to determine which subtype a entity belongs to. It's possible to rename and decide which value is stored on a per class basis.

If you are not happy with this you two other strategies to choose from.

  • Table per Class
  • Join

Please refer to the documentation for more information.

willcodejavaforfood
Thanks, changing QuestionHeader to TABLE_PER_CLASS solved it.
dcp
Hope that works for you :)
willcodejavaforfood