Foreign key dependency checking

Dear all:
I have a question about foreign key checking.
Let's say I have two Z table, one is master table and one is transaction table.
The master table contains a primary key named CustNo.
The transaction table have two primary keys named CustNo and OrderNo.
The CustNo has foreign key (mandt + CustNo) point to master table, with setting
"Key fields/candidates  1:N"
I expected that, delete record in master table should check if there is any dependency in the transaction table,
but I am wrong.  I am able to delete anything in master table even there are records in transaction table using the same CustNo.
My question is, how can I make the dependency check?
Thanks in advance.
Edited by: Hung Kai, Michael Cheng on Nov 3, 2008 5:29 AM

Hello,
    For this u need to change the cardinality.
Below are the list of cardinalities and their functionality.Chack it and use the proper one.
The left side (n) of the cardinality is defined as follows:
n=1: There is exactly one record assigned to the check table for each record of the foreign key table.
n=C: The foreign key table may contain records which do not correspond to any record of the check table because the foreign key field is empty. This can occur for example if the field of the foreign key table is optional, in which case it does not have to be filled.
The right side (m) of the cardinality is defined as follows:
m=1: There is exactly one dependent record for each record of the check table.
m=C: There is at most one dependent record for each record of the check table.
m=N: There is at least one dependent record for each record of the check table.
m=CN: There may be any number of dependent records for each record of the check table.
Shafi

Similar Messages

  • Use of foreign key check in ABAP reports

    Hi,
    I'm trying to understand if it's possible to use a foreign key integrity check in an ABAP reports. I have understood that this kind of check is deactivated for performance reasons, is it right?
    In this case I'd like to know if it is possible to activate the foreign key check "on demand", or just for a particular table.
    As an example, I'd like to use the foreign key defined on attribute AKONT of table KNB1, that points on the related attribute of table SKB1.
    Thanks,
    Gabriele

    Welcome on SCN!
    I'm trying to understand if it's possible to use a foreign key integrity check in an ABAP reports. I have understood that this kind of check is deactivated for performance reasons, is it right?
    Most likely yes. Integrity is turned OFF for Open SQL statements but is turned ON for screen fields.
    If you just create screen parameter like
    parameters pa_akont type knb1-akont.
    ...then input help for that field will be automatically provided. This means that you will not be able to pick or enter value different that this allowed from SKB1 table (foreign key relationship will be checked).
    You can explicitly assign different input help or search help for certain screen field independently of type it is refering i.e by means of fm F4IF_FIELD_VALUE_REQUEST .
    This however still relates only to screen fields, not fields used directly in ABAP statement.
    Regards
    Marcin

  • Creating a pseudo foreign key trigger

    hi
    i want to create a trigger that will act like a foreign key and check whether the value being entered already exists in two separate tables. I want it to not allow entry if the id already exists in: either none of the tables; or both the tables.
    I have tried to create the following trigger, it compiles, but doesnt do the job :(
    create or replace trigger trig_test1
    before insert on TEST3
    referencing old as old new as new
    for each row
    DECLARE
    cursor cur_check_test1 is
    select PKONE
    from TEST1, TEST3
    where PKONE = TEST3.PKTHREE;
    CURSOR CUR_CHECK_TEST2 IS
    SELECT PKTWO
    FROM TEST2, TEST3
    WHERE PKTWO = TEST3.PKTHREE;
    v_key_conflict EXCEPTION;
    v_test1_temp varchar2(1);
    v_test2_temp varchar2(1);
    BEGIN
    OPEN cur_check_test1;
    FETCH cur_check_test1 into v_test1_temp;
    if (((cur_check_test1%FOUND) AND (cur_check_test2%found)) or ((cur_check_test1%notfound) and (cur_check_test2%notfound)))
    then close cur_check_test1;
    close cur_check_test2;
    RAISE v_key_conflict;
    else
    close cur_check_test1;
    close cur_check_test2;
    end if;
    EXCEPTION
    WHEN v_key_conflict then
    raise_application_error(-20111, 'parent key constraint violated');
    end;
    Can someone please help me out. cheers

    What business requirement are you trying to meet?
    It's going to be difficult to correctly implement this kind of constraint using triggers, because:
    1. You will need to handle updates on TEST3, not just inserts.
    2. You will need to handle inserts, updates, and deletes on both TEST1 and TEST2.
    3. You will need some sort of locking mechanism to prevent concurrent transactions from violating the constraint (because they can't see the changes that other transactions have made but have not yet committed).
    In other words, it might be on the order 10 times more complicated to implement this kind of constraint using triggers than you originally thought. Before pursuing the trigger approach further, it might be worth looking into some alternatives. Is the benefit of implementing the constraint worth the effort? Are there some "creative" ways you can use declarative (built-in) constraints instead? Would restructuring your tables help?

  • EMIGALL : problem of foreign key

    Hi everybody
    I m working on a EMIGALL migration and i met one problem with foreign key…
    My field VKONT is defined (in specific table ZR006SAT) like a foreign key with check table FKKVK (Contract Account Header). It means that an entry can be inserted in ZR006SAT , only if VKONT value exists in FKKVK table.
    But, during the migration of my migration object ZR006SAT (same name as the table), I have no error when I put any value for my VKONT field in the input file. EMIGALL does not control the foreign key constraint and I don’t understand why (???).
    However,
    1.     when i try to insert manually (by SE11) an entry in ZR006SAT, SAP forces me to input correct value (existing in FKKVK table) for VKONT field.
    2.     for standards migration objects, there is no problem… foreign key check is working well
    3 days I ve been on this problem.
    Please help me

    Hai
    You can find detailed documentation of EMIGALL in SAP itself. Use Transaction EQ81 to display it. It provides all the concepts and procedures to work with EMIGALL. I will also prepare a document and send it to u later. Meanwhile just for ur info here are some points about EMIGALL :
    1. It Migrates data Business Object wise
    2. It uses Direct Input Technique
    3. It has more than 100 objects of IS-U
    and the steps for implementation goes like this:
    1)You have to create a user specially for migration which will have all the authorizations related to migration workbench, BASIS and IS-U
    2)You have to create your own company in EMIGALL. There is a default company called SAP.
    3)Company SAP contains all the Business Objects
    4)You have to figure out what business objects u need and then u have to copy those business objects to ur company from Standard Company SAP
    5)Each objects contains more than one structure and each structure can contain more than one fields. The relation goes like this
    Object ---> Structure ---> Field
    6)You have to define field rules for each required field of the object. You have to mark "Not required" for fields u don't need
    7)After field rules for a given object is set u have to generate load report i.e. actual Direct Input Program which will migrate data. This program is generated on basis of field rules set by u.
    8)After the load report is generated u have to prepare an input file (import File) for migration. The import file should be according to structure provided by SAP and must be in binary format. SAP Provides the structure of file according to your configurations. You have to write ur own Data conversion program(in any language) for this task.
    9)You take import file as input and migrate the data using generated load program
    10)Finally u can check the Migration Statistics and Error Log
    Regards
    Sreeni

  • Data Workshop; identifing Foreign keys

    Good morning ~
    I am having some difficulty loading tables from Excel, utilizing the Data Workshop. The tables and data do load, however, it is not giving me an opportunity to identify foreign key relationships in tables which already exist. It is allowing Primary keys and sequences to be identified, but I am not being given the opportunity to identify foreign key relationships. From past experience, I remember always being given the opportunity to identify foreign key relationships, and I am confused as to why I am not being given that option now.
    Any and all help would be greatly appreciated!
    All the best,
    -Robert

    I don't seem to get it right,
    I have three tables, like in the figure in my initial post.
    In table CHILD_A  I create a foreign key (with check required) linked to the field ID in the table MAIN.
    When I add a new record to the table MAIN, I get the error message that I defined in the foreign key.
    What I expected was this error to occur when I added a field to table CHILD_A that didn't have a corresponding record in table MAIN.

  • Foreign Key Relationship.

    Hi,
    I asked a question in the link below(which I solved).
    https://social.msdn.microsoft.com/Forums/en-US/514a4f48-b1fa-4fe7-bc2b-4c252b34cf50/insertion-of-null-value?forum=vbgeneral
    Here my question is that:
    We make relation of foreign keys to enforce user for accurate data insertion, but sometime we do need null values to be passed to attribute that is used as
    Foreign key. We studied and know that Foreign keys are meant to except null values, which it doesn't(In simple way. I mean when we select an attribute as foreign key and check it to except nulls, then it should.)
    As I explained in the upper link how I solved the problem, if similar problems have to be solved like that then,
    Why we define Foreign Key over there, i mean it could be done without defining the Foreign key?
    If it is necessary in any meaning then why we Enforce Foreign
    Key Constraint as No,
    to except nulls from user?
    What effects does Enforce Foreign Key Constraint as No
    gives to Foreign Key Constraints?
    Thnx in advance.
    Habib Ur Rehman

    Hello Habib,
    I do not think what you are seeing is normal and without having the exact DDL it will be hard to comment.
    I suspect,  you may had "NOT NULL" constraint on the foreign key column. thats why it is not allowing NULLs.
    By definition, Foreign Key maintains(enforces) referential integrity and does allows NULLs. So,  you should be able to enter nulls without having to disable the foreign key enforcement.  
    by setting
    Enforce Foreign Key Constraint to NO, you are effectively disabling the enforcement. you are invalidating the whole purpose of the constraint. 
    The purpose of having that option(disabling foreign key) is to fasten the data load process bypassing the check(extra work) to make sure the value exists in the primary key table when importing large amounts of data.  But to maintain the referential
    integrity you should have that enabled.
    I am not sure without having the ddl, where you did wrong.PLEASE POST YOUR DDL and it should be clear where it went wrong for you. but i hope this script below should help you understand...
    CREATE TABLE [dbo].[Make]([sid] [int] NULL unique,[sname] [varchar](50) NULL)
    go
    CREATE TABLE [dbo].[Make_FK]([sno] [int] NULL unique,[sname] [varchar](50) NULL,[sid] [int] NULL
    CONSTRAINT FK_MAKE FOREIGN KEY (sid) REFERENCES dbo.make (SID))
    insert into make(sid,sname)
    values(1,'sam')
    insert into dbo.Make_FK(sno,sname,sid)
    values(100,'somename',null)
    select * from Make
    --sid is null. SID is the foreig n key referring to sid in MAKE table.
    select * from Make_FK
    Hope it Helps!!

  • Foreign Key check in ALV Grid

    Hi all.
    I'm trying to have data automatically validated using Foreign Keys in an (editable) ALV Grid.  I managed to get the proper values in a dropdown on F4, but i want the manual entries validated without coding every field individually.
    The field in question is LFA1-REGIO.  This field has a Foreign Key in T005S.  I'm using F.M. DDIF_TABL_GET to populate my Field Catalog.  This gives me all Foreign Key fields for my fields.
    If the user enters 'ZZ' as a Region(LFA1-REGIO), the auto-validation of CL_GUI_ALV_GRID does not recognize that this value is invalid.
    I've debugged the class methods that handle the validation, but it seems the problem is in the way i'm setting up my Foreign Key info.
    Could someone tell me how to set this up properly?  i also have access to the dependant field LAND1, and would like to integrate it in the Validation, but this is a second priority.  Thanks in advance.

    Hi Jester,
      In your ALV Grid Field Catalog (LVC_S_LAYO), for REGIO check whether field <b>checktable</b> has value T005S and <b>ref_field</b> has REGIO and <b>ref_table</b> has LFA1.
      If the above entries are fine and still the validation does not occur then try changing the ref_table to T005S and see..
      Hope this helps..
    Sri

  • Editable ALV & Foreign Key Check

    I am working on an Editable ALV. Here if I try to enter some value into a field which doesnt exist in the corresponding Check table of the field, ALV throws me an error. This scenario is working fine.
    But in some scenarios I populate the ALV table from a Z table (Z table has the same strucutre as the ALV table) and then show this to the user as an editable ALV but in this scenarios if some erroneous values exist in my Z table for a particular fieId I am not getting the Foreign Key check I mentioned earlier.  Here I was hoping to get error message after SET_TABLE_FOR_FIRST_DISPLAY !
    I am using CL_GUI_ALV_GRID, has anyone found a workaround for this
    Antony

    Hi Antony,
    you can INHERIT a class from CL_GUI_ALV_GRID and then redefine SET_TABLE_FOR_FIRST_DISPLAY adding the raising EVENT data_changed for all cells.
    Regards,
    Clemens

  • Problem with Foreign Key check in an editable ALV

    Hi,
    I've implemented an editable ALV.
    The underlying context node is referenced to a structure and within the structure the foreign keys are defined.
    In my example, I have two editable columns with different foreign key checks.
    My problem is, the foreign key check works only for one column.
    So if I enter in both columns incorret values, only a message for the first column is thrown,
    but not for the second column!
    Only if I enter two errors in one(!) column (in two rows), than I get two error messages.
    Examples:
    does not work:
    COL1 | COL2
    err1  | err2   -> only one error message is displayed (for err1)
    It works in this case:
    COL1 | COL2
    err1  |  ok
    err2  |  ok
    => two messages for err1 and err2
    and in this case
    COL1 | COL2
    err1  |  ok
    ok     |  err2
    => two messages for err1 and err2
    I've found nothing in OSS. My system is a 7.00 with SP18, so OSS 1153492 is already implemented.
    Do I somenthing wrong or is this an error in SAP?
    Thanks,
    Andreas

    Hi Lekha,
    thank you very much for your support!
    I try to give you an example.
    In general, you need an editable ALV with at least two columns.
    The node for the ALV table in the component controller has to be assigned to a dictionary structure!
    That is very important, otherwise the foreign key check will not work!
    And the two fields in this dictionary structure have to be assigned to a "check table".
    Prerequisition: NW70 SP16 or higher! See oss note 1153492.
    Maybe an easy way to reproduce it is using the WD component WDT_FLIGHTLIST_EDIT.
    So copy this component to a Z-component.
    Than create a dictionary structure for the node "NODE_FLIGHTTAB" with the same 10 fields as the node attributes.
    In your new dictionary structure, assign to the fields CARRID and CONNID the check tables SCARR and SPFLI. (see table SFLIGHT).
    Than make both columens (CARRID and CONNID) editable.
    This has to be done in the "RESULTVIEW" in the method "INIT".
    You can user the following code:
      lr_column = lr_column_settings->get_column( 'CARRID' ).
      create object lr_input_field
        exporting
          value_fieldname = 'CARRID'.
      lr_column->set_cell_editor( lr_input_field ). 
      lr_column = lr_column_settings->get_column( 'CONNID' ).
      create object lr_input_field
        exporting
          value_fieldname = 'CONNID'.
      lr_column->set_cell_editor( lr_input_field ).
    Copy this code below this code:
      lr_column_settings ?= l_value.
      lr_column = lr_column_settings->get_column( 'PRICE' ).
      create object lr_input_field
        exporting
          value_fieldname = 'PRICE'.
      lr_column->set_cell_editor( lr_input_field ).
    Than just activate all,  create a Web Dynpro Application and your are ready to test it.
    To test it, do the following:
    Append/Insert an empty row.
    Enter a CARRID and CONNID that does not exist and press ENTER.
    My result: only one error message is displayed for the wrong CARRID, but no error message for CONNID!
    Insert a new row.
    Enter in the first row, column CARRID an invalid value and in the second(!) row in column CONNNID.
    Than you get two(!) error messages. That's the behavior I expect.
    So thank you very much in advance for your help!
    Regards,
    Andreas

  • Check constraint/foreign key combination

    I would like to add a constraint (check, FK, or otherwise) that forces a value to be either -1 OR be in a foreign table.  The statement below is invalid because you can't use subqueries, but I think it's clear what I'm trying to do.  Can anyone
    suggest a different approach?
    Thanks!
    ALTER TABLE cfg.ClientFieldThreshold ADD CONSTRAINT CK_cfg_ClientFieldThreshold_DBListID
    CHECK (DBListID = -1 OR DBListID IN (SELECT ID FROM dbo.vwClientDatabases)
    /* the subquery here isn't allowed */

    3 ways to do this. 
    1) use NULL instead of -1 as the value that does not have to be in the foreign table.  Then you just need a normal foreign key (because a foreign key column that contains NULL is not checked against the foreign table.  Sample code to do this
    Create Table FooParent(ParentID int primary key);
    Create Table FooChild(ChildId int primary key, ParentID int Null, Constraint FooChildFK Foreign Key(ParentID) References FooParent);
    go
    -- Can add row with NULL
    Insert FooChild(ChildId, ParentID) Values (1, Null);
    go
    -- But cannot add row with any other value that is not in FooParent
    Insert FooChild(ChildId, ParentID) Values (2, 25);
    go
    -- Check result
    Select * From FooChild;
    go
    Drop Table FooChild;
    go
    Drop Table FooParent;
    2) Add a dummy row to the parent table with a primary key of -1.  Then, of course, all you need is a foreign key constraint.
    3) Add a persisted computed column that is NULL whenever your column that you want to enforce the constraint against is equal to -1, otherwise just the value in that column.  Then create a foreign key on the computed column.  Sample code
    Create Table FooParent(ParentID int primary key);
    Create Table FooChild(ChildId int primary key, ParentID int Not Null, AlteredParentID As NULLIF(ParentID, -1) Persisted, Constraint FooChildFK Foreign Key(AlteredParentID) References FooParent);
    go
    -- Can add row with -1
    Insert FooChild(ChildId, ParentID) Values (1, -1);
    go
    -- But cannot add row with any other value that is not in FooParent
    Insert FooChild(ChildId, ParentID) Values (2, 25);
    go
    -- Check result
    Select * From FooChild;
    go
    Drop Table FooChild;
    go
    Drop Table FooParent;
    Tom

  • Quality Check view foreign key

    Headstart Ruleframe Designer6i
    Running utility quality check view definition
    Report states that complete property for _CG foreign key must be set to "NO" to keep from being generated in DB. However if foreign key is used in formmodule error CDG-3436 is raised : " Invalid Linkage ". I'm I correct in assuming that Complete property has to be set to "YES" and Validation property to "CLIENT" to avoid the errors?

    You are correct. I will log this as a bug in the quality check report.
    Thanks,
    Lauri

  • To check the foreign keys

    i need to know the table which gives a mapping of foreign keys...that is the key name its own table and then the table to which it is mapped as a foreign key

    Hi 477390,
    Here is the query.
    col "Primary Table" forma a30
    col "Primary Key constraint" forma a30
    col "Child Table" forma a30
    col "Reference Key constraint" forma a30
    select a.table_name "Primary Table"
         ,a.constraint_name "Primary Key constraint"
         ,b.table_name "Child Table"
         ,b.constraint_name "Reference Key constraint"
    from      dba_constraints a
         ,dba_constraints b
    where a.constraint_name=b.r_constraint_name
    and a.owner='<SCHEMA_NAME>';
    Cheers,
    Kamalesh JK

  • Foreign Key Relationships to external associations - Is it really this dodgy or is there a better way?

    Hi All,
    Let's picture that I have a GW service called Search Helps and within that service I have a PersonalAreas Entity Set which acts as a search help for drop down fields effectively that need to select a Personal Area.  I have 3 properties, with Personal Area Id and Company Code being the keys, and the text for Personal Area being the 3rd and last property. You really need to filter PersonalAreas by Company Code otherwise it's a fairly useless result set.
    Now within a different GW service, I have an entity called Position which has a single key of PositionId.  There is also a a property of company code on this Position.
    Now rather than asking the UI developer to get the Company code value and filter PersonalAreas with it directly, I thought it would be nicer for the UI developer just to use the navigation from a specific Position to PossiblePersonalAreas.  e.g. Positions('123')/PossiblePersonalAreas returns the entity set of PersonalAreas filtered by the Position's Company Code.
    So with that in mind, I add the external model reference pointing at the search helps service; then create an external association via the sneaky External Associations Editor button (that doesn't appear on the Wizard just to confuse you), and set up my Dependent entity to point at the Search Helps PersonalAreas entity.
    At this point I really want to tie the Position's Company Code to the PersonalAreas Company Code, but all I can do is set up a referential constraint of PositionId to CompanyCode or have no referential constraint at all (note - in my example I added the referential constraint as there is an issue with navigation keys being provided to external associations from what I can tell - more about this below).
    So, without any other option, I go into my GetEntitySet method of PersonalAreas and write something like the following:
      CASE iv_source_name.
        WHEN 'Position'.
          READ TABLE it_filter_select_options ASSIGNING <filter> INDEX 1.
          CHECK sy-subrc = 0.
          READ TABLE <filter>-select_options assigning <select_option> INDEX 1.
          CHECK sy-subrc = 0.
          position_id = <select_option>-low.
    *     Get company code for position
          TRY.
              CREATE OBJECT o_position
                EXPORTING
                  i_position_id = position_id.
              o_position->get_cost_centre_information(
                IMPORTING
                  e_company_code = company_code
            CATCH zcx_hr_object.
          ENDTRY.
      endcase.
    * Continue with retrieving PersonalAreas for given Company Code
    <Remaining code not shown>
    e.g. I have to assume CompanyCode is actually "Position Id" when the source of this call is from Position (I could also look at the navigation to find this has come from Position but if you're wondering, unfortunately for external associations, the key is not included in this for some reason but the same followup logic of reloading the object would be required).
    So the question I'm hoping the answer to is Yes is: Am I missing something in my understanding here?
    Thanks,
    Matt
    Edit since posting and playing around a bit more: Thinking about this further - it's unfortunate, but the navigation property in odata really implies the dependent entity has knowledge of the principal entity and realistically must know how to instantiate it if it needs to get data based on one of the properties. 
    Now while I'm fine with that (sort of) I think it's wrong that the dependent entity needs to have the required key properties to hold the principal entities as it makes something like a generic search help impossible to do with navigation - Maybe I just need to be done with that and expect filters to be used by UI programmers to find foreign key'ed entities....

    Hi Matt,
    I'm not surprised that you have an issue with this. One bugbear I have with Gateway is that for some reason the designers don't think any context beyond the immediate preceding navigation node is important. They don't support this within the same service,so it's hardly likley to work in a service reference.
    I may be wrong but I don't think GW is OData compliant in this respect. If I have the navigation path /blindservice/FromHereSet(1)/ToAPoints(22)/ToBPoints, it's rather restrictive to say I cannot see the initial key of '1' in the path when I am trying to resolve 'ToBPoints'. If that value - where I started - is key to the context, I have to know it.
    Currently the only way to access this context is to embed the 'key history' in the intermediate entities, i.e. /blindservice/FromHereSet(1)/ToAPoints(1,22)/ToBPoints. In my view that is corrupting the URl to suit the limitations of the SAP OData implementation. What's even more confusing/frustrating is that the technical request context appears to be able to store the stacked navigation keys but doesn't make use of this design. 
    I feel your pain
    Ron.

  • Caching problem w/ primary-foreign key mapping

    I have seen this a couple of times now. It is not consistent enough to
    create a simple reproducible test case, so I will have to describe it to you
    with an example and hope you can track it down. It only occurs when caching
    is enabled.
    Here are the classes:
    class C1 { int id; C2 c2; }
    class C2 { int id; C1 c1; }
    Each class uses application identity using static nested Id classes: C1.Id
    and C2.Id. What is unusual is that the same value is used for both
    instances:
    int id = nextId();
    C1 c1 = new C1(id);
    C2 c2 = new C2(id);
    c1.c2 = c2;
    c2.c1 = c1;
    This all works fine using optimistic transactions with caching disabled.
    Although the integer values are the same, the oids are unique because each
    class defines its own unique oid class.
    Here is the schema and mapping (this works with caching disabled but fails
    with caching enabled):
    table t1: column id integer, column revision integer, primary key (id)
    table t2: column id integer, column revision integer, primary key (id)
    <jdo>
    <package name="test">
    <class name="C1" objectid-class="C1$Id">
    <extension vendor-name="kodo" key="jdbc-class-map" value="base">
    <extension vendor-name="kodo" key="table" value="t1"/>
    </extension>
    <extension vendor-name="kodo" key="jdbc-version-ind"
    value="version-number">
    <extension vendor-name="kodo" key="column" value="revision"/>
    </extension>
    <field name="id" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-field-map" value="value">
    <extension vendor-name="kodo" key="column" value="id"/>
    </extension>
    </field>
    <field name="c2">
    <extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
    <extension vendor-name="kodo" key="column.id" value="id"/>
    </extension>
    </field>
    </class>
    <class name="C2" objectid-class="C2$Id">
    <extension vendor-name="kodo" key="jdbc-class-map" value="base">
    <extension vendor-name="kodo" key="table" value="t2"/>
    </extension>
    <extension vendor-name="kodo" key="jdbc-version-ind"
    value="version-number">
    <extension vendor-name="kodo" key="column" value="revision"/>
    </extension>
    <field name="id" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-field-map" value="value">
    <extension vendor-name="kodo" key="column" value="id"/>
    </extension>
    </field>
    <field name="c1">
    <extension vendor-name="kodo" key="dependent" value="true"/>
    <extension vendor-name="kodo" key="inverse-owner" value="c2"/>
    <extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
    <extension vendor-name="kodo" key="table" value="t1"/>
    <extension vendor-name="kodo" key="ref-column.id" value="id"/>
    <extension vendor-name="kodo" key="column.id" value="id"/>
    </extension>
    </field>
    </class>
    </package>
    </jdo>
    Because the ids are known to be the same, the primary key values are also
    used as foreign key values. Accessing C2.c1 is always non-null when caching
    is disabled. With caching is enabled C2.c1 is usually non-null but sometimes
    null. When it is null we get warnings about dangling references to deleted
    instances with id values of 0 and other similar warnings.
    The workaround is to add a redundant column with the same value. For some
    reason this works around the caching problem (this is unnecessary with
    caching disabled):
    table t1: column id integer, column id2 integer, column revision integer,
    primary key (id), unique index (id2)
    table t2: column id integer, column revision integer, primary key (id)
    <jdo>
    <package name="test">
    <class name="C1" objectid-class="C1$Id">
    <extension vendor-name="kodo" key="jdbc-class-map" value="base">
    <extension vendor-name="kodo" key="table" value="t1"/>
    </extension>
    <extension vendor-name="kodo" key="jdbc-version-ind"
    value="version-number">
    <extension vendor-name="kodo" key="column" value="revision"/>
    </extension>
    <field name="id" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-field-map" value="value">
    <extension vendor-name="kodo" key="column" value="id"/>
    </extension>
    </field>
    <field name="c2">
    <extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
    <extension vendor-name="kodo" key="column.id" value="id2"/>
    </extension>
    </field>
    </class>
    <class name="C2" objectid-class="C2$Id">
    <extension vendor-name="kodo" key="jdbc-class-map" value="base">
    <extension vendor-name="kodo" key="table" value="t2"/>
    </extension>
    <extension vendor-name="kodo" key="jdbc-version-ind"
    value="version-number">
    <extension vendor-name="kodo" key="column" value="revision"/>
    </extension>
    <field name="id" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-field-map" value="value">
    <extension vendor-name="kodo" key="column" value="id"/>
    </extension>
    </field>
    <field name="c1">
    <extension vendor-name="kodo" key="dependent" value="true"/>
    <extension vendor-name="kodo" key="inverse-owner" value="c2"/>
    <extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
    <extension vendor-name="kodo" key="table" value="t1"/>
    <extension vendor-name="kodo" key="ref-column.id" value="id2"/>
    <extension vendor-name="kodo" key="column.id" value="id"/>
    </extension>
    </field>
    </class>
    </package>
    </jdo>
    Needless to say, the extra column adds a lot of overhead, including the
    addition of a second unique index, for no value other than working around
    the caching defect.

    Tom-
    The first thing that I think of whenever I see a problem like this is
    that the equals() and hashCode() methods of your application identity
    classes are not correct. Can you check them to ensure that they are
    written in accordance to the guidelines at:
    http://docs.solarmetric.com/manual.html#jdo_overview_pc_identity_application
    If that doesn't help address the problem, can you post the code for your
    application identity classes so we can double-check, and we will try to
    determine what might be causing the problem.
    In article <[email protected]>, Tom Landon wrote:
    I have seen this a couple of times now. It is not consistent enough to
    create a simple reproducible test case, so I will have to describe it to you
    with an example and hope you can track it down. It only occurs when caching
    is enabled.
    Here are the classes:
    class C1 { int id; C2 c2; }
    class C2 { int id; C1 c1; }
    Each class uses application identity using static nested Id classes: C1.Id
    and C2.Id. What is unusual is that the same value is used for both
    instances:
    int id = nextId();
    C1 c1 = new C1(id);
    C2 c2 = new C2(id);
    c1.c2 = c2;
    c2.c1 = c1;
    This all works fine using optimistic transactions with caching disabled.
    Although the integer values are the same, the oids are unique because each
    class defines its own unique oid class.
    Here is the schema and mapping (this works with caching disabled but fails
    with caching enabled):
    table t1: column id integer, column revision integer, primary key (id)
    table t2: column id integer, column revision integer, primary key (id)
    <jdo>
    <package name="test">
    <class name="C1" objectid-class="C1$Id">
    <extension vendor-name="kodo" key="jdbc-class-map" value="base">
    <extension vendor-name="kodo" key="table" value="t1"/>
    </extension>
    <extension vendor-name="kodo" key="jdbc-version-ind"
    value="version-number">
    <extension vendor-name="kodo" key="column" value="revision"/>
    </extension>
    <field name="id" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-field-map" value="value">
    <extension vendor-name="kodo" key="column" value="id"/>
    </extension>
    </field>
    <field name="c2">
    <extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
    <extension vendor-name="kodo" key="column.id" value="id"/>
    </extension>
    </field>
    </class>
    <class name="C2" objectid-class="C2$Id">
    <extension vendor-name="kodo" key="jdbc-class-map" value="base">
    <extension vendor-name="kodo" key="table" value="t2"/>
    </extension>
    <extension vendor-name="kodo" key="jdbc-version-ind"
    value="version-number">
    <extension vendor-name="kodo" key="column" value="revision"/>
    </extension>
    <field name="id" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-field-map" value="value">
    <extension vendor-name="kodo" key="column" value="id"/>
    </extension>
    </field>
    <field name="c1">
    <extension vendor-name="kodo" key="dependent" value="true"/>
    <extension vendor-name="kodo" key="inverse-owner" value="c2"/>
    <extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
    <extension vendor-name="kodo" key="table" value="t1"/>
    <extension vendor-name="kodo" key="ref-column.id" value="id"/>
    <extension vendor-name="kodo" key="column.id" value="id"/>
    </extension>
    </field>
    </class>
    </package>
    </jdo>
    Because the ids are known to be the same, the primary key values are also
    used as foreign key values. Accessing C2.c1 is always non-null when caching
    is disabled. With caching is enabled C2.c1 is usually non-null but sometimes
    null. When it is null we get warnings about dangling references to deleted
    instances with id values of 0 and other similar warnings.
    The workaround is to add a redundant column with the same value. For some
    reason this works around the caching problem (this is unnecessary with
    caching disabled):
    table t1: column id integer, column id2 integer, column revision integer,
    primary key (id), unique index (id2)
    table t2: column id integer, column revision integer, primary key (id)
    <jdo>
    <package name="test">
    <class name="C1" objectid-class="C1$Id">
    <extension vendor-name="kodo" key="jdbc-class-map" value="base">
    <extension vendor-name="kodo" key="table" value="t1"/>
    </extension>
    <extension vendor-name="kodo" key="jdbc-version-ind"
    value="version-number">
    <extension vendor-name="kodo" key="column" value="revision"/>
    </extension>
    <field name="id" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-field-map" value="value">
    <extension vendor-name="kodo" key="column" value="id"/>
    </extension>
    </field>
    <field name="c2">
    <extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
    <extension vendor-name="kodo" key="column.id" value="id2"/>
    </extension>
    </field>
    </class>
    <class name="C2" objectid-class="C2$Id">
    <extension vendor-name="kodo" key="jdbc-class-map" value="base">
    <extension vendor-name="kodo" key="table" value="t2"/>
    </extension>
    <extension vendor-name="kodo" key="jdbc-version-ind"
    value="version-number">
    <extension vendor-name="kodo" key="column" value="revision"/>
    </extension>
    <field name="id" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-field-map" value="value">
    <extension vendor-name="kodo" key="column" value="id"/>
    </extension>
    </field>
    <field name="c1">
    <extension vendor-name="kodo" key="dependent" value="true"/>
    <extension vendor-name="kodo" key="inverse-owner" value="c2"/>
    <extension vendor-name="kodo" key="jdbc-field-map" value="one-one">
    <extension vendor-name="kodo" key="table" value="t1"/>
    <extension vendor-name="kodo" key="ref-column.id" value="id2"/>
    <extension vendor-name="kodo" key="column.id" value="id"/>
    </extension>
    </field>
    </class>
    </package>
    </jdo>
    Needless to say, the extra column adds a lot of overhead, including the
    addition of a second unique index, for no value other than working around
    the caching defect.
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Using FOreign key constraints on tables in database.

    I am student and novice in the field of ORACLE and PL/SQL and Database Creation. I had created a database consisting tables and got problem while applying foreign key constraints.
    CUST_MSTR
    CREATE TABLE "DBA_BANKSYS"."CUST_MSTR"("CUST_NO" VARCHAR2(10),
    "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25), "LNAME" VARCHAR2(25),
    "DOB_INC" DATE NOT NULL,      "OCCUP" VARCHAR2(25), "PHOTOGRAPH" VARCHAR2(25),
    "SIGNATURE" VARCHAR2(25), "PANCOPY" VARCHAR2(1),      "FORM60" VARCHAR2(1));
    (CUST_NO is PRIMARY KEY, )
    -- EMP_MSTR
    CREATE TABLE "DBA_BANKSYS"."EMP_MSTR"("EMP_NO" VARCHAR2(10),
    "BRANCH_NO" VARCHAR2(10), "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25),
    "LNAME" VARCHAR2(25), "DEPT" VARCHAR2(30), "DESIG" VARCHAR2(30));
    (EMP_NO is primary key )
    --NOMINEE_MSTR
    CREATE TABLE "DBA_BANKSYS"."NOMINEE_MSTR"("NOMINEE_NO" VARCHAR2(10),
    "ACCT_FD_NO" VARCHAR2(10), "NAME" VARCHAR2(75), "DOB" DATE,
    RELATIONSHIP" VARCHAR2(25));
    (NOMINEE_NO is primary key )
    --ADDR_DTLS
    CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
    "CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
    "ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
    "PINCODE" VARCHAR2(6));
    ( ADDR_NO is primary key )
    Problem: I want to apply foreign key constraints on ADDR_DTLS table so that Before inserting value in ADDR_DTLS table it must check, VALUE in ADDR_DTLS.CODE_NO must be PRESENT either in attribute value CUST_MSTR.CODE_NO or EMP_MSTR.CODE_NO or NOMINEE_MSTR.CODE_NO table .
    I applied the foreign key constraints using this syntax
    CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
    "CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
    "ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
    "PINCODE" VARCHAR2(6),
    constraints fk_add foreign key CODE_NO references CUST_MSTR. CODE_NO,
    constraints fk_add1 foreign key CODE_NO references EMP_MSTR. CODE_NO,
    constraints fk_add2 foreign key CODE_NO references NOMINEE_MSTR.CODE_NO);
    (foreign key)
    ADDR_DTLS.CODE_NO ->CUST_MSTR.CUST_NO
    ADDR_DTLS.CODE_NO ->NOMINEE_MSTR.NOMINEE_NO
    ADDR_DTLS.CODE_NO ->BRANCH_MSTR.BRANCH_NO
    ADDR_DTLS.CODE_NO ->EMP_MSTR.EMP_NO
    When I applied foreign key constraints this way, its gives a error called foreign key constraints violation. (I understand that, its searches the attribute value of ADDR_DTLS.CODE_NO in all the three tables must be present then the value will be inserted. But I want, if the value is in any of the three table then its should insert the value or its gives an error.)
    Please help me out, though i put the question and i want too know how to apply the forign key in this way. and is there any other option if foreign key implementation is not pssible.

    If you are on 11g you can use ON DELETE SET NULL:
    CREATE TABLE addr_dtls
    ( addr_no          NUMBER(6)  CONSTRAINT addr_pk PRIMARY KEY
    , addr_cust_no     CONSTRAINT addr_cust_fk    REFERENCES cust_mstr    ON DELETE SET NULL
    , addr_emp_no      CONSTRAINT addr_emp_fk     REFERENCES emp_mstr     ON DELETE SET NULL
    , addr_nominee_no  CONSTRAINT addr_nominee_fk REFERENCES nominee_mstr ON DELETE SET NULL
    , addr_type        VARCHAR2(1)
    , addr1            VARCHAR2(50)
    , addr2            VARCHAR2(50)
    , city             VARCHAR2(25)
    , state            VARCHAR2(25)
    , pincode          VARCHAR2(6) );In earlier versions you'll need to code some application logic to do something similar when a parent row is deleted, as otherwise the only options are to delete the dependent rows or raise an error.
    btw table names can be up to 30 characters and don't need to end with MSTR or DTLS, so for example CUSTOMERS and ADDRESSES might be more readable than CUST_MSTR and ADDR_DTLS. Also if the Customer/Employee/Nominee PKs are generated from a sequence they should be numeric.
    Edited by: William Robertson on Aug 15, 2010 6:47 PM

Maybe you are looking for

  • Excel 2007 Slow Opening File

    We were looking at migrating to Office 2007. To verify compatibility, several key users have loaded Office 2007 on their machines. There seems to be several problems related to opening files in Excel. If Excel is open and the user does a File/Open, f

  • Modifying a flex column chart

    Hi there, I'm trying to change the x axis to have four bars that measure categories. My bars show up, and track data, but are so thin and only in the far left quadrent. Chart         <mx:ColumnChart id="categoryChart" height="137" color="0x323232"   

  • ALL Photos missing after Time Machine restore  (help)

    So, I accidently formated the wrong drive while in Windows, (big oops) which gave me the opportunity to take Time Machine for a test drive. I put the DVD in, and was able to restore from the TIme Machine drive. Very impressed! Everything came back ju

  • Need SSO Tutorials

    Hi guyz, I am new to SSO and would like to understand the technology I googled and found commercial articles on SSO. Can someone plz point out some useful online resources on SSO which are not vendor specific. Thanx -a-lot. Deep

  • Issues with Adobe Application Manager

    Adobe Application Manager We've encountered the following issues: Sorry, there seems to be a problem with th installation process (Error code A12E1) For troubleshooting tips, please visit our customer support page.