Hi,

I have the problem that a NULL is entered into my table instead of the value
of the foreign key.
I have the following mapping specified:

<mapping>
    <class name="cat.Product" identity="id" key-generator="Unique">
        <description>Product definition</description>
        <map-to table="product" />
        <field name="id" type="string">
            <sql name="id" type="varchar" />
        </field>
        <field name="name" type="string">
            <sql name="name" type="char" />
        </field>
    </class>

    <class name="cat.Order" identity="id" key-generator="Unique">
        <description>An order</description>
        <map-to table="orders" />
        <field name="id" type="string">
            <sql name="id" type="varchar" />
        </field>
        <field name="orderDate" type="date">
            <sql name="orderdate" type="date" />
        </field>
        <field name="orderItems" type="castortest.OrderItem" required="true"
collection="collection">
            <sql many-key="orderid"/>
        </field>
    </class>

    <class name="cat.OrderItem" identity="id" depends="castortest.Order"
key-generator="Unique">
        <description>An order</description>
        <map-to table="orderitem" />
        <field name="id" type="string">
            <sql name="id" type="varchar" />
        </field>
        <field name="product" type="castortest.Product">
            <sql name="productid" />
        </field>
        <field name="quantity" type="integer">
            <sql name="quantity" type="integer" />
        </field>
        <field name="order" type="castortest.Order">
            <sql name="orderid" />
        </field>
    </class>

    <key-generator name="UUID" alias="Unique"/>

</mapping>

When I use the following sequence to create a new order then the productid
column in order item
is always NULL:

            Product p = null;
            .
            .
            db = jdo.getDatabase();

            db.begin();

            query = db.getOQLQuery(oql);
            qr    = query.execute();

            if (qr.hasMore()) {
                p = (Product) qr.next();
            }

            db.commit();

            db.begin();

            Order       order = new Order();
            OrderItem item = new OrderItem();
            item.setOrder(order);
            item.setProduct(p);
            item.setQuantity(1);
            order.addOrderItem(item);

            db.create(order);

            db.commit();
            db.close();

The strange this is that this only happens when I use a key-generator for
Product. When I remove
the key-generator attribute then it works fine in this context. Can anyone
tell me what I did wrong?

Kind regards,

Lothar

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

Reply via email to