Hi all,
        I've been using Castor for a few days now, and think it's fantastic - why 
haven't I been using O-R/XML tools before?!  

However, I'm starting to do some more complex mapping and really getting stumped.  I 
want to go from an RDBMS schema, to an Object Model, and then marshall to XML

I have the following RDBMS table schema:

+-------------------+     +----------------+
| CARDS             |     | NOTES          |
+-------------------+     +----------------+
| cardid(#) VARCHAR |<----| cardid VARCHAR |
| ...               |     | id(#)  NUMBER  |
+-------------------+     | text   VARCHAR |
                          +----------------+

(This is a one-to-many mapping - each entry in the CARDS table can have many NOTEs in 
the NOTES table


I have the following Beans  (! Below, I have removed all my package naming so as to 
increase readability !)

//CARD

public class Card
  implements java.io.Serializable {
...
    private String id;
    public String       getId()  { return this._id; }
    public void setId(String id) { this._id = id; }

    private Notes  _notes = new Notes();
    public Notes  getNotes() { return this._notes; }
    public void setNotes(Notes notes)  { this._notes = notes; }
...
}

// NOTES
public class Notes
  implements java.io.Serializable {
    private String _cardid;
    public String getId() { return this._cardid; }
    public void setId(String id) { this._cardid = id; }

    private Vector    _notes = new Vector();
    public Vector        getNotes()       { return this._notes; }
    public void addNote(Note note)  { _notes.add(note); }
}

//NOTE
public class Note
  implements java.io.Serializable {
    private String _note;
    private int _id;
    private String _cardid;

    public String getNote() {return this._note;}
    public void setNote(String note) {this._note = note;}
    public int getId() {return this._id;}
    public void setId(int id) {this._id = id;}
    public String getCardid() {return this._cardid;}
    public void setCardid(String cardid) {this._cardid = cardid;}
}

Basically, I want to wrap alll the note elements into a collection in a Notes object


Now I am using the following mapping.xml:


<mapping>
  <class name="Card" identity="id">
    <map-to table="cards"/>
    ...
    <field name="notes" type="Notes"/>
  </class>

  <class name="Notes" identity="id">
    <field name="id" type="string"/>
    <field name="notes" type="Note" collection="vector">
      <sql many-key="cardid"/>
    </field>
  </class>

  <class name="Note" identity="id">
    <map-to table="notes"/>
    <field name="id" type="integer"/>
    ...
    <field name="note" type="string">
      <sql name="text"/>
    </field>
  </class>
</mapping>


Now you can see that the Notes object does not have a corresponding table that it maps 
to - it's just a wrapper for the collection.  How does the cardid get passed from the 
Card mapping to the Notes mapping and thus onto the Note mapping?  Is the mapping 
correct?

Regardless, it seems that no matter what I do to the Notes mapping above, I get the 
following error message:

org.exolab.castor.mapping.MappingException: Field element, "Notes"  not found!

Where is this going wrong?
Am I approaching this wrapping correctly?


Any feedback would be appreciated (and thanks for reading this far if you've got this 
far!)

Pete

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

Reply via email to