Thanks for the info, but still I have issues. I'm using castor 0.9.5.

When I save the PollConfiguration object, it gets saved but without any ids
for a PollSite and PollView object(even though in the test harness they are
set).

When I step through, I see that the objects are in the PollConfiguration
object right before db.create(obj), but when I check the DB, they're not
persisted and no error is thrown.

I'm attaching the code in question and the mapping file. It's pretty light.
Please help, I'm sure I've just got a wrong setting or something.

-I






(See attached file: mapping.xml)(See attached file: PollConfiguration.java)
(See attached file: PollAnswer.java)(See attached file: PollView.java)(See
attached file: PollQuestion.java)(See attached file: PollSite.java)(See
attached file: CastorConfigTest.java)


|---------+--------------------------->
|         |                           |
|         |                           |
|         |           [EMAIL PROTECTED]|
|         |           com             |
|         |                           |
|         |           07/15/2003 03:28|
|         |           AM              |
|         |           Please respond  |
|         |           to castor-dev   |
|         |                           |
|---------+--------------------------->
  
>---------------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                                 |
  |        To:      [EMAIL PROTECTED]                                                  
                             |
  |        cc:                                                                         
                                 |
  |        Subject: Re: [castor-dev] mapping/relationship issues                       
                                 |
  
>---------------------------------------------------------------------------------------------------------------------|




Hello Ian,

The start point is to write Java classes for it, like you already have a
mapping:

public class PoolConfiguration {
  private int id;
  private ArrayList questions = new ArrayList();

  // Default getters and setters

  public void addQuestion(Question question) {
     if (!questions.contains(question)) {
        questions.add(question);

        // Here provide backseting for question
        // If if many-to-many
        // question.addConfigurationPool(this);

        // If it one-to-many
        question.setConfigurationPool(this);
     }
  }
}

public class Question {
  private int id;
  private PoolConfiguration poolConfiguration;
  private ArrayList answers = new ArrayList();

  // Default getters and setters

  public void addAnswer(Answer answer) {
     if (!answers.contains(answer)) {
        answers.add(answer);

        // Here provide backseting for answer
        // If if many-to-many
        // answer.addQuestion(this);

        // If it one-to-many
        answer.setQuestion(this);
     }
  }
}

public class Answer {
  private int id;
  private Question question;

  // Default getters and setters
}


Now you have clear picture to build mapping file:
    <class name="com.sonymusic.poll.PollConfiguration" identity="id"
key-generator="MAX">
        <map-to table="poll_configuration"/>
        <field name="id" type="integer">
            <sql name="id" type="integer"/>
        </field>
        <field name="questions" type="com.sonymusic.poll.Question"
collection="arraylist" required="true">
           <sql many-key="poolconfiguration_id"/>
        </field>
    </class>
    <class name="com.sonymusic.poll.Question" identity="id"
key-generator="MAX">
        <map-to table="questions"/>
        <field name="id" type="integer">
            <sql name="id" type="integer"/>
        </field>
        <field name="answers" type="com.sonymusic.poll.Answer"
collection="arraylist" required="true">
            <sql many-key="question_id"/>
        </field>
        <field name="poolConfiguration"
type="com.sonymusic.poll.PollConfiguration">
            <sql name="poolconfiguration_id" />
        </field>
    </class>
    <class name="com.sonymusic.poll.Answer" identity="id"
key-generator="MAX">
        <map-to table="answers"/>
        <field name="id" type="integer">
            <sql name="id" type="integer"/>
        </field>
        <field name="question" type="com.sonymusic.poll.Question">
            <sql name="question_id" />
        </field>
    </class>

BTW, I have the troubles, when I try to do testing system, where
Question have many ansvers and one right ansver. Castor now not allow to
do this, you must use simple id field instead:

public class Question {
  private int id;
  private PoolConfiguration poolConfiguration;
  private ArrayList answers = new ArrayList();
  private int rightAnsverId;

  // Default getters and setters

  public void addAnswer(Answer answer) {
     if (!answers.contains(answer)) {
        answers.add(answer);

        // Here provide backseting for answer
        // If if many-to-many
        // answer.addQuestion(this);

        // If it one-to-many
        answer.setQuestion(this);
     }
  }
}

Thanks!

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 15, 2003 12:24 AM
To: [EMAIL PROTECTED]
Subject: [castor-dev] mapping/relationship issues




I'm sure I've got this wrong.

Bascially, I'm attempting to use a 1-to-many structure between questions
and answers, with each question having multiple answers. And each
PollConfiguration object having multiple Question objects. Can Castor
support this?

Am I doing something wrong? I tried to mimic the examples as much as
possible.

Here is the mapping:

 <class name="com.sonymusic.poll.PollConfiguration" identity="id"
key-generator="MAX">
        <description>Object representing poll
configurations</description>
        <map-to table="poll_configuration"/>
        <field name="id" type="integer">
            <sql name="poll_config_id" type="integer"/>
        </field>
               <field name="pollView" type="com.sonymusic.poll.PollView"
>
            <sql name="poll_view_id"/>
        </field>
        <field name="pollSite" type="com.sonymusic.poll.PollSite" >
            <sql name="poll_site_id"/>
        </field>
        <field name="questions" type="com.sonymusic.poll.PollQuestion"
collection="vector" required="true">
           <sql many-key="poll_question_id"/>
        </field>
    </class>
    <class name="com.sonymusic.poll.PollQuestion" identity="id"
key-generator="MAX">
        <description>
            Object representing poll questions
        </description>
        <map-to table="poll_questions"/>
        <field name="answers" type="com.sonymusic.poll.PollAnswer"
collection="vector" required="true">
            <sql many-key="poll_answer_id"/>
        </field>
        <field name="id" type="integer">
            <sql name="poll_question_id" type="integer"/>
        </field>
        <field name="question" type="string" dirty="check">
            <sql name="poll_question" type="varchar"/>
        </field>
    </class>
    <class name="com.sonymusic.poll.PollAnswer" identity="id"
key-generator ="MAX">
        <description>
            Object representing poll answers
        </description>
        <map-to table="poll_answers"/>
        <field name="questionId" type="integer">
            <sql name="poll_question_id" type="integer"/>
        </field>
        <field name="id" type="integer">
            <sql name="poll_answer_id" type="integer"/>
        </field>
        <field name="barGraphColor" type="string">
            <sql name="poll_answer_bargraphcolor" type="varchar"/>
        </field>
        <field name="answer" type="string" required="true">
            <sql name="poll_answer" type="varchar"/>
        </field>
    </class>
    <class name="com.sonymusic.poll.PollView" identity="id"
key-generator ="MAX">
               <map-to table="poll_view"/>
        <field name="id" type="integer">
            <sql name="poll_view_id" type="integer"/>
        </field>
        <field name="titleText" type="string">
            <sql name="poll_view_titletext" type="varchar"/>
        </field>

          </class>

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

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




Attachment: mapping.xml
Description: Binary data

Attachment: PollConfiguration.java
Description: Binary data

Attachment: PollAnswer.java
Description: Binary data

Attachment: PollView.java
Description: Binary data

Attachment: PollQuestion.java
Description: Binary data

Attachment: PollSite.java
Description: Binary data

Attachment: CastorConfigTest.java
Description: Binary data

Reply via email to