One to many relationship

From: Alex Gunawan Wibowo (netzone_tec..ahoo.com)
Date: Thu Nov 25 2004 - 05:05:14 EST

  • Next message: Todd O'Bryan: "Re: One to many relationship"

    Hello..

    Apology in advance if this is rather a very simple
    question for many of you..

    First, let me explain the database schema..

    there are 3 tables..

    subcategory, category, and item.

    category has PK "category name",
    subcategory has composite PK of : "category name" &
    "subcategory name". (as it is connected to category
    table)
    item has it's own PK, item ID.. but in addition, it
    stores a foreign key of "category name" & "subcategory
    name" (as it is connected to "subcategory" table).

    Hope that's clear enough.
    Now, the problem is that i have an entry from "item"
    table.

    when i call
    anItem.getToSubCategory().getSubCategory()
    -> getToSubCategory() supposed to return a SubCategory
       object.
    -> getSubCategory() supposed to return a String, i.e.
        one of the PK.
    both method are generated by CayenneModeller.
    it says "too many objects.." (CayenneRuntimeException
    is thrown). Can't exactly remember what the error
    says.. but it's along the line of saying that there
    are too many object in the subcategory table that has
    "OTHER" as the "subcategory" field. This is because
    "anItem" has as it's entry "OTHER" as the
    "subcategory" and "bla" as the "category".

    I have a little difficulty in understanding the
    problem here. I know that there are a lot of of entry
    in the
    table "subcategory" that has "OTHER" as the field
    entry..(since it's a composite PK anyway).

    So can anyone tell me how i can retrieve the foreign
    key "subcategory" for "anItem" object above??
    The way I mentioned above works in Hibernate.. and I
    don't know why it does not work in Cayenne..
    What amuses me more is that the call above seems to
    make a connection to the database.
    (In Hibernate, "anItem" object above would have
    "SubCategory" object as one of it's field.. so the
    method above works perfectly ok).

    Basically, what I want is the "subcategory" field (of
    type "String") from the "anItem" object. I don't want
    the "SubCategory" object that I can get easily using
    anItem.getToSubCategory()

    Thanks a lot for the help!

    Best regards,

    Alex.

                    
    __________________________________
    Do you Yahoo!?
    The all-new My Yahoo! - Get yours free!
    http://my.yahoo.com
     



    This archive was generated by hypermail 2.0.0 : Thu Nov 25 2004 - 05:05:25 EST