Werner,
FYI.
--------------- part of db schema ---------------
CREATE TABLE `question` (
`id` int(11) unsigned NOT NULL default '0',
`subject` text NOT NULL,
`answer` int(11) unsigned default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
);
CREATE TABLE `questionoption` (
`id` int(11) unsigned NOT NULL default '0',
`question` int(11) unsigned default NULL,
`value` varbinary(255) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
);
----- Original Message -----
From: "Werner Guttmann" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 04, 2004 4:12 AM
Subject: Re: [castor-user] [JDO] A collection and an object refer to the same type
>
> Sean,
>
> re-reading your reply, I wonder how your database schemas actually look like ?
>
> Regards
> Werner
>
> On Thu, 17 Jun 2004 21:25:12 +0800, Sean Liang wrote:
>
>>Werner,
>>
>>You must be correct. I thought that option model just has to know which question it
>>belongs to.
>>
>>Can you explain what happens after the question.setAnswer(B) is invoked? On the
>>option model sides, A, B and C are all the same, but why only A is
> removed, B can be got from both question.option and question.answer?
>>
>>What will you do in my situation? How can I mark the correct answer of a question?
>>
>>Thanks,
>>Sean
>>----- Original Message -----
>>From: "Werner Guttmann" <[EMAIL PROTECTED]>
>>To: <[EMAIL PROTECTED]>
>>Sent: Thursday, June 17, 2004 6:28 PM
>>Subject: Re: [castor-user] [JDO] A collection and an object refer to the same type
>>
>>
>>>
>>> Sean,
>>>
>>> I guess your problems are a direct consequence of not modelling the relations
>>> correctly. In your example, you have two relations, a 1:1 (question -
>>> answer) and a 1:M relation (question - options). As far as the entity
>>> model.Question is concerned, you are fine as you have defined both relations,
>>> indeed.
>>>
>>> But on the model side of things, you've defined only one member named 'question'.
>>> Is this the return leg of the question - answer or questions -
> options
>>> relation ?
>>>
>>> I guess you see what I mean ...
>>>
>>> Werner
>>>
>>> On Thu, 17 Jun 2004 14:25:15 +0800, Sean Liang wrote:
>>>
>>> >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
>>>
>
>
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-user
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user