Anyone who has the experience in using collection, please kindly take a look at my code and show me a way.
 
------------- part of mapping file -----------
<class identity="id" key-generator="HIGH-LOW" name="model.Tournament">
    <map-to table="tournament" />
        <field name="id" type="integer">
            <sql name="id" type="integer" />
        </field>
        <field name="highScore" type="model.HighScore" collection="collection">
            <sql many-key="tournament" />
        </field>
</class>
<class identity="id" key-generator="HIGH-LOW" name="model.HighScore">
    <map-to table="highscore" />
        <field name="id" type="integer">
            <sql name="id" type="integer" />
        </field>
        <field name="score" type="double">
            <sql name="score" type="double" />
        </field>
        <field name="tournament" type="model.Tournament">
            <sql name="tournament" />
        </field>
</class>
 
------------- part of Tournament.java -----------
    private Collection highScoreList = new ArrayList();
    public void addHighScore(HighScore highScore) {
        highScoreList.add(highScore);
        highScore.setTournament(this);
    }
    public Collection getHighScore() {
        return highScoreList;
    }
It then gives me an exception:
org.exolab.castor.jdo.DataObjectAccessException: no method to set value for field: model.HighScore in class: ClassMolder model.Tournament
 at org.exolab.castor.persist.FieldMolder.setValue(FieldMolder.java:347)
 at org.exolab.castor.persist.ClassMolder.revertObject(ClassMolder.java:2562)
 at org.exolab.castor.persist.LockEngine.revertObject(LockEngine.java:848)
 at org.exolab.castor.persist.TransactionContext.rollback(TransactionContext.java:1760)
 at org.exolab.castor.jdo.engine.DatabaseImpl.rollback(DatabaseImpl.java:569)
 ......
 
It seems that the setter is required for the collection type? But I didn't find it in the Product.java of JDO example.
 
After adding the setter method:
------------- part of Tournament.java -----------
    public void setHighScore(Collection list) {
        highScoreList = list;
    }
It tells me a warning this time:
org.exolab.castor.persist.CollectionProxy$ColProxy add
Warning: FieldMolder FieldMolder of model.Tournament.sethighScore(model.HighScore highScore) is not addable; collection needs to set for object type model.HighScore.
I was confused, could anybody provide me a good practice of collection mapping in JDO?
 
 
Thanks,
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