Hi -

I'm having a problem with object references being null'd when I commit()
seemingly unrelated information.

Summary: Objects of type Product have an array of SalesScenario objects.
SalesScenario has the corresponding reference to a single Product (mapping
to follow).  It is also important that the Product maintain exactly one
*current* scenario, so I implemented that as an additional reference to a
SalesScenario in the Product class.

When I set the currentScenario for the first time, everything goes fine.
However, when I subsequently change it, the *previous* SalesScenario has its
Product reference set to null!  This is reproducible.  In fact, it happens
every time.

Example code:

// begin example
            db = JDOSingleton.getInstance().getJDO().getDatabase();
            db.begin();

            OQLQuery pquery =
                    db.getOQLQuery("SELECT p FROM
com.tryarc.forecast.Product p WHERE p.id=$1");
            pquery.bind(productID);
            QueryResults presults = pquery.execute();
            product = (Product)presults.next();

            OQLQuery squery =
                    db.getOQLQuery("SELECT s FROM
com.tryarc.forecast.Scenario s WHERE s.id=$1");
            squery.bind(scenarioID);
            QueryResults sresults = squery.execute();
            Scenario scenario = (Scenario)sresults.next();

            Scenario former = product.getCurrentScenario();
            product.setCurrentScenario(scenario);
            if(former != null){
                former.setProduct(product); // it's *still* set to null,
even after adding this line
            }

            db.commit();
            db.close();
// end example

This is all wrapped in a try/catch block, but it never throws exceptions.
It occurs to me that there might be a problem with the fact that the Product
comes from a different query than the Scenario, but how else do you fetch
objects of disparate types like that?

Also, the mapping:

    <class name="com.tryarc.forecast.Product"
        identity="id" key-generator="IDENTITY">
        <map-to table="Products"/>
        <field name="id" type="integer">
            <sql name="ProdID" type="integer" />
        </field>

        <!-- many non-scenario-related fields... -->

        <field name="currentScenario" type="com.tryarc.forecast.Scenario">
            <sql name="Prod_CurrScenario"/>
        </field>
        <field name="scenarios" type="com.tryarc.forecast.Scenario"
            collection="vector">
            <sql many-key="Scen_ProductID"/>
        </field>
    </class>

    <class name="com.tryarc.forecast.Scenario"
        identity="id" key-generator="IDENTITY">
        <map-to table="Scenarios"/>
        <field name="id" type="integer">
            <sql name="ScenarioID" type="integer"/>
        </field>

        <field name="product" type="com.tryarc.forecast.Product">
            <sql name="Scen_ProductID"/>
        </field>
    </class>


Thanks for any help,
_________________________________

 Robert Kent  -  (617) 413-3510
     http://www.rjk-comm.com/
_________________________________

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

Reply via email to