Re: Strange behaviour with creating an object

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Oct 30 2003 - 12:42:03 EST

  • Next message: Andrus Adamchik: "[ANN] Using JIRA for ObjectStyle bug tracking"

    On Oct 30, 2003, at 11:16 AM, Axel HONFI wrote:
    > Hello!
    >
    > I create a blank object and then I set the primary_key (to dept
    > PKs)-objects. With every object I set cayenne fires off a select-query
    > for
    > all the same objects with only this one parameter set.
    > This returns sometimes around 11000 records, as the PK is a composite
    > of 2
    > FK-PKs and one String field. Is there a way to avoid this - or did I
    > screw
    > up?
    >
    > Thanks for any help,
    >
    > Axel

    Hi Axel,

     From you past emails I understand that your schema in question is
    something like:

    A ->> B <<-C

    With B being a meaningful join table. This "unexpected" fetch occurs
    when setting the relationship B -> A or B -> C. The reason why it
    happens is cause when you set a relationship, Cayenne by default
    attempts to update a reverse relationship (if you set B -> A, Cayenne
    will also try to set A -> B if it can). Since B->A is yet unresolved,
    it fetches objects form this relationship, hence the query that you are
    observing.

    Permanent Solution: Now, it doesn't have to be that way. Cayenne can be
    smarter and do not resolve to-many relationship until it absolutely has
    to be resolved, and instead maintain all recently added objects
    separately. I've been contemplating this solution for a while. I think
    it is important and I will try to fix it soon.

    Temporary solution: You can use a simple workaround in your case. E.g.
    instead of this code from your previous message:

    WebPage page = (WebPage)ctxt.createAndRegisterNewObject("WebPage");
    page.setToWebContext(webcontext_object);
    page.setToWebLanguage(weblanguage_object);

    You can do this:

    WebPage page = (WebPage)ctxt.createAndRegisterNewObject("WebPage");
    page.setToOneTarget("toWebContext", webcontext_object, false);
    page.setToOneTarget("toWebLanguage", weblanguage_object, false);

    Hope this helps.
    Andrus



    This archive was generated by hypermail 2.0.0 : Thu Oct 30 2003 - 12:42:07 EST