RE: EO model validation, relations and foreign keys

From: Bill Michell (bill.michel..bc.co.uk)
Date: Thu Sep 28 2006 - 09:50:48 EDT

  • Next message: Andrus Adamchik: "Cc'ying new Jira tasks to this list"

    I believe that this is mentioned explicitly in the docs, but in a
    different context:
    http://developer.apple.com/documentation/WebObjects/Enterprise_Objects/E
    nterpriseObjects/chapter_3_section_11.html#//apple_ref/doc/uid/TP3000101
    1-CH203-TPXREF148

    In other words, validation definitely happens before primary key
    generation!

    In order to reproduce the problem, create a new EO as the master, and
    immediately create a detail EO and add it to the relationship. The
    master doesn't yet have a PK, so the FK field cannot be set to anything
    useful.

    When you save the changes, you appear to get the exception because of
    the null FK field *before* the PK is assigned!

    Or are Zak and I simply missing a step in the operation?

     

    -- 
    Bill Michell 
    Development Team Leader, Broadcast Platforms, BBC News Interactive. 
    

    -----Original Message----- From: Zak Burke [mailto:zdbw..artmouth.EDU] Sent: 17 August 2006 21:23 To: woproject-de..bjectstyle.org Subject: Re: EO model validation, relations and foreign keys

    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.

    http://www.bbc.co.uk/ This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this.



    This archive was generated by hypermail 2.0.0 : Thu Sep 28 2006 - 09:50:50 EDT