Re: Can not recognize the object passed in for the toOne relationship?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Apr 21 2006 - 02:35:47 EDT

  • Next message: Bill Fan: "RE: Can not recognize the object passed in for the toOne relationship?"

    Hi Bill,

    Many-to-one relationships usually work without surprises. Can you
    check a few more things right before commit:

    Log.debug("prices: " + product.getPriceArray());
    Log.debug("product: " + price.getToProduct());

    Andrus

    On Apr 21, 2006, at 8:41 AM, Bill Fan wrote:

    > Hi,
    >
    > I'm trying to do something like the following and it seems the
    > productId
    > becomes null in the generated sql query.
    >
    > Price price = new Price();
    > threadDataContext().registerNewObject(price);
    > price.setToProduct(product);
    > price.setPrice(o.getPrice());
    > ...
    >
    > The query generated was as following:
    > ------------------------------------
    > INSERT INTO dbo.Price (Description, GST, IsUnitPrice, Price, PriceId,
    > PriceTypeId, ProductId, Qty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
    > [bind: '1 box', 10, 'true', 100, 280, 1, NULL, 1]
    >
    >
    > I'm using Tomcat 5.0.28 + Spring 1.2.7 + Cayenne 1.1.4 + Struts 1.2.9
    >
    > I can see and verify the productId value and the product name by
    > placing the
    > following logging statements before the product object is used,
    > Log.debug("product Id: " + product.getProductId());
    > Log.debug("product Name: " + product.getProductName());
    >
    >
    >
    >
    > More details are as follow if it is required:
    > =============================================
    > In the web app, there are a Product table and a Price table. It is
    > a "one to
    > many" relation from Product to Price,
    >
    > The tables:
    > -----------
    > Product table:
    > proudctId int PK
    > productName varchar(100)
    > ...
    >
    > Price table:
    > priceId int PK,
    > productId int FK (to Product.ProductId column)
    > price double
    > ...
    >
    > Cayenne data map:
    > -----------------
    > <db-relationship name="toProduct" source="Price" target="Product"
    > toMany="false">
    > <db-attribute-pair source="ProductId" target="ProductId"/>
    > </db-relationship>
    >
    > <db-relationship name="priceArray" source="Product" target="Price"
    > toMany="true">
    > <db-attribute-pair source="ProductId" target="ProductId"/>
    > </db-relationship>
    >
    >
    > Many thanks in advance!
    > Bill



    This archive was generated by hypermail 2.0.0 : Fri Apr 21 2006 - 02:36:13 EDT