Re: EO model validation, relations and foreign keys

From: Zak Burke (zdbw..artmouth.EDU)
Date: Thu Aug 17 2006 - 16:23:27 EDT

  • Next message: Joshua Archer: "Re: [OT] Need assistance getting ant builds working..."

    Chuck Hill wrote on 8/17/06 1:42 PM:
    > It sounds more like the relationship is not defined correctly. Are you
    > propagating the primary key (or should you be)? Is the PK of some time
    > that EOF can't generate?

    Hmmmm. Key propagation is an interesting idea but I don't think that's
    the problem here. The model is defined like this:

            DLOrganization <<--> DLEntity

    and all entities have their own PKs (which are just integers from the
    eo_pk_table; nothing fancy there) with no key propagation in any
    direction. If I turn on DLEntity.organizations() key propagation, then I
    get no PKs for new DLOrganization objects.

    It really seems to me like model-validation is happening before primary
    key generation but I'm not sure how to confirm that. When I log the
    objects in my EC prior to save changes, all the objects are there, but
    only with EOTemporaryGlobalID fields, i.e. the primary key and foreign
    key fields are empty for all new objects.

    For the record, here are the relationship bindings I'm using:

    DLOrganization.entity()
               deleteRule = EODeleteRuleCascade;
               destination = DLEntity;
               isMandatory = Y;
               isToMany = N;
               joinSemantic = EOInnerJoin;
               joins =
               ({
                      destinationAttribute = entityId;
                      sourceAttribute = entityId;
               });
               name = entity;
               ownsDestination = Y;
           },

    DLEntity.organizations()
               deleteRule = EODeleteRuleDeny;
               destination = DLOrganization;
               isToMany = Y;
               joinSemantic = EOInnerJoin;
               joins =
               ({
                      destinationAttribute = entityId;
                      sourceAttribute = entityId;
               });
               name = organizations;
               ownsDestination = N;
               propagatesPrimaryKey = N;
           },

    Slightly off-topic but on a related note, is there a good, thorough
    explanation of modeling, relationships and key propagation besides
    Apple's Chapter 5 of Using EOModeler? I've been buffaloed by some of
    these settings in the past where there are multiple ways to do things
    and EOF and I expect different outcomes. What I really want is not a
    description of each setting in isolation, but a description of what
    settings to use for a given type of relationship.

    Likewise, the Enterprise Objects text doesn't have enough detail about
    how saveChanges works to help me debug this problem. It identifies
    "Referential integrity enforcement" and "Key generation" as different
    phases in the save process, but doesn't explicitly mention them, or the
    order they occur in, in the "Flow of Data During a Save" section. Grrrrr.

    Thanks for the pointers. I'll keep investigating the relationship
    settings to see if anything turns up.

    zak.

    > On Aug 17, 2006, at 7:25 AM, Zak Burke wrote:
    >
    >> I posted this note to the webobjects-dev list a few days ago but didn't
    >> get any bites, so maybe it's a woproject issue, or maybe it's my own
    >> code that is causing these issues. At any rate...
    >>
    >> When I validate a model using the woproject Entity Modeler, it complains
    >> if a class has a relationship with the Optionality marked as "Mandatory"
    >> but the join-field marked as optional. If I make both the relationship
    >> and the foreign-key required, however, EOF complains in
    >> EOEditingContext.saveChanges() that the foreign key can't be null:
    >>
    >> Validation failed on an object [org.thei3p.eo.DLOrganization]
    >> with keypath = entityId and exception: The entityId property of
    >> DLOrganization is not allowed to be null.
    >>
    >> It seems to me that the Entity Modeler gets the constraints right but
    >> that EOF is doing validation before it generates keys for the DB tables.
    >>
    >> Is there any way to force EOF to generate its EO keys before checking
    >> the validity of the EOs to be persisted?
    >>
    >> Thanks,
    >>
    >> zak.



    This archive was generated by hypermail 2.0.0 : Thu Aug 17 2006 - 16:23:36 EDT