Please take a look at the following snippet:

 <class identity="id" key-generator="HIGH-LOW" name="model.Question">
        <map-to xml="question" table="question" />
        <field name="id" type="integer">
            <sql name="id" type="integer" />
        </field>
        <field name="subject" type="string">
            <sql name="subject" type="varchar" />
        </field>
        <field name="option" type="model.Option" collection="collection">
            <sql many-key="question" />
        </field>
        <field name="answer" type="model.Option">
            <sql name="answer" />
        </field>
    </class>

    <class identity="id" key-generator="HIGH-LOW" name="model.Option">
        <map-to xml="questionoption" table="questionoption" />
        <field name="id" type="integer">
            <sql name="id" type="integer" />
        </field>
        <field name="question" type="model.Question">
            <sql name="question" />
        </field>
        <field name="value" type="string">
            <sql name="value" type="varchar" />
        </field>
    </class>

As what you can see, a Question contains several possible options, one of which is the 
correct answer. That is, option and answer in the Question refer to the same type 
"model.Option".

Let's say we have a question with 3 options A, B, C.

The first time I call question.setAnswer(A), it is totally fine. But the next time I 
call question.setAnswer(B), guess what? Option A is removed from question.option 
collection and in the database A.question is set to null.

I tried this stupid code:

    Option a = question.getAnswer();
    question.setAnswer(b);
    a.setQuestion(question);

but it still doesn't work. I don't have idea about how to solve this problem now.

Could you provide me any suggestion for that? Thanks in advance.

Sean
----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to