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

Similar Messages

  • Missing primary foreign key in grandchild table

    I have a model with a two inheritance generations.
    https://www.dropbox.com/s/4rghqcmxx24bgvt/pf_logical.png
    When I engineer all entities everything is fine. The child tables get their primary foreign keys:
    https://www.dropbox.com/s/t4v5bexxwdrn5y1/pf_engineered.png
    But when I do not engineer the child generation the grandchildren have no primary foreign keys anymore.
    https://www.dropbox.com/s/ofl436sm8dua3w8/pf_missing.png
    I have expected, that the grandchildren get a primary foreign key to the grandfather. But that is not the case. How can I tell the modeler to engineer such a foreign key?

    Hi,
    thanks for reporting the problem. I logged a bug for that.
    Philip

  • Foreign key Mapping based on Data - in SQL Developer Data modeler

    Team
    Do SQL Developer Data modeler supports Foreign Key mapping based on the Data in the Schema rather defined at the DDL ? For e.g if we implement a Objects Relation ship mapping in Data base, we don't define Foreign keys at table creation.
    Toad does this feature through "AUTOMATIC FOREIGN KEYS MAPPING IN TOAD DATA MODELER" more info at (http://toadworld.com/Blogs/tabid/67/EntryId/905/Automatic-Foreign-Keys-Mapping-in-Toad-Data-Modeler.aspx)
    any one know how to implement through some scripts also helps me
    Regards
    Raj

    If you have table PKs defined and the candidate columns match those PK columns, then you can use the Discover Foreign Keys utility. Right mouse over the relational model name (node) in the left browser. It is about half way down the menu. I did a blog post about it last week on kentgraziano.com.

  • Query Builder recognizing primary/foreign key

    Is there a way to have Query Builder recogninze the primary/foreign keys of the tables when they are selected? Right now it looks like you have to manually join the tables together by selected the column(s) to join.
    Thanks

    You can define a query key[1] 'planId' on InvestmentOption for the PLAN_OID column. That'll let you write an expression like the one below which does not produce a join. The nice part about the query key is that it does not require you to add attributes to your object in order to query o them.
    Expression plan = new ExpressionBuilder();
    Expression where = plan.get("planId").equal(somePlanId);--Shaun
    [1] http://www.oracle.com/technology/products/ias/toplink/doc/10131/main/_html/descfg010.htm#sthref3039

  • ODI not able to detect primary/foreign keys from XML- user lacks privilege or object not found

    Hi Guys,
    Im trying to load an xml file with two entities address and employee as below. The topology reverse engineering everything works fine. Im even able to view the xml data  in ODI,  but when i try to load the data from these two entities joining by the schema primary keys and foreign keys which odi created on reverse engineering process for xml, im getting the below error.  Im able to load data from one entity, error only occurs when i use the join odi creates internally to identify the xml components employee and address
    XML File:
    <?xml version="1.0" encoding="UTF-8" ?>
    <EMP>
    <Empsch>
    <Employee>
    <EmployeeID>12345</EmployeeID>
    <Initials>t</Initials>
    <LastName>john</LastName>
    <FirstName>doe</FirstName>
    </Employee>
    <Address>
    <WorkPhone>12345</WorkPhone>
    <WorkAddress>Test 234</WorkAddress>
    </Address>
    </Empsch>
    </EMP>
    Topology:  jdbc:snps:xml?f=C:/Temp/RR/Empsch.xml&s=Empsch&re=EMP&dod=true&nobu=false
    Error Message:
    -5501 : 42501 : java.sql.SQLException: user lacks privilege or object not found: EMPSCH.EMPSCHPK
    java.sql.SQLException: user lacks privilege or object not found: EMPSCH.EMPSCHPK
        at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
        at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
        at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
        at com.sunopsis.jdbc.driver.xml.SnpsXmlConnection.prepareStatement(SnpsXmlConnection.java:1232)
        at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at oracle.odi.core.datasource.dwgobject.support.OnConnectOnDisconnectDataSourceAdapter$OnDisconnectCommandExecutionHandler.invoke(OnConnectOnDisconnectDataSourceAdapter.java:200)
        at $Proxy2.prepareStatement(Unknown Source)
        at oracle.odi.runtime.agent.execution.sql.SQLCommand.doInitializeStatement(SQLCommand.java:83)
        at oracle.odi.runtime.agent.execution.sql.SQLCommand.getStatement(SQLCommand.java:117)
        at oracle.odi.runtime.agent.execution.sql.SQLCommand.getStatement(SQLCommand.java:111)
        at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:81)
        at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:1)
        at oracle.odi.runtime.agent.execution.DataMovementTaskExecutionHandler.handleTask(DataMovementTaskExecutionHandler.java:70)
        at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2913)
        at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2625)
        at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:577)
        at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:468)
        at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2128)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$2.doAction(StartSessRequestProcessor.java:366)
        at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:300)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$0(StartSessRequestProcessor.java:292)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.doExecute(StartSessRequestProcessor.java:855)
        at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:126)
        at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:82)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: EMPSCH.EMPSCHPK
        at org.hsqldb.error.Error.error(Unknown Source)
        at org.hsqldb.ExpressionColumn.checkColumnsResolved(Unknown Source)
        at org.hsqldb.QueryExpression.resolve(Unknown Source)
        at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
        at org.hsqldb.ParserCommand.compilePart(Unknown Source)
        at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
        at org.hsqldb.Session.compileStatement(Unknown Source)
        at org.hsqldb.StatementManager.compile(Unknown Source)
        at org.hsqldb.Session.execute(Unknown Source)
        ... 27 more
    Please advice
    Thanks
    Revanth

    Thats obvious from the xml file contents you have given here. In this xml file You have four complex type. Two of them are employee and address. However the employee doesnot have any relation with address as you have not added the relationship. Thats why its failing. Its not the fault of ODI.
    Also I would suggest not to use auto generated dtd by ODI as you might face problem in future. For example the address type of XML has 8 attributes and 4 of them are not mandatory. That means each of your xml file may have attributes between 4 to 8.  This is where ODI auto generated DTD fails.
    XML Schema complexType Element
    Thanks
    Bhabani

  • Creation of Index for Primary & Foreign Key required?

    hi,
    i would like to find out if a column is defined as the primary key, do i need to create a separate index for it? or defining a primary key will tell the db to automatically create an index for it?
    does foreign key have the same behavior as the primary key constraint?
    thanks!

    i would like to find out if a column is defined as the primary key, do i need to create a separate index for it? No
    or defining a primary key will tell the db to automatically create an index for it? Yes
    See
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg05itg.htm#7265
    does foreign key have the same behavior as the primary key constraint?No. See http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg05itg.htm#1574

  • Foreign key mapped to a unique constraint

    ok here is the issue
    create table parent(col1 char, col2 char);
    alter table parent add constraint pk_parent primary key(col1);
    alter table parent add constraint uk_parent unique(col1,col2);
    insert into parent values('A','7');
    *1 row created.*
    create table child(col1 char, col2 char);
    alter table child add constraint fk_child_parent foreign key(col1,col2) references parent(col1,col2);
    insert into child values('B','4');
    insert into child values('B','4')
    ERROR at line 1:
    ORA-02291: integrity constraint (WILDGOD.FK_CHILD_PARENT) violated - parent key
    not found
    thats what i expect....but
    insert into child values('B',NULL);
    *1 row created.*
    why does it let me do this, i realize its because col2 is NULL but shouldnt it still check for col1 to be in the parent?
    Please clarify, thanks in advance.

    I see the same & am not sure why either.
    SQL> @a
    SQL> create table parent(col1 char, col2 char);
    Table created.
    SQL> alter table parent add constraint pk_parent primary key(col1);
    Table altered.
    SQL> alter table parent add constraint uk_parent unique(col1,col2);
    Table altered.
    SQL>
    SQL> insert into parent values('A','7');
    1 row created.
    SQL> create table child(col1 char, col2 char);
    Table created.
    SQL> alter table child add constraint fk_child_parent foreign key(col1,col2) references parent(col1,col2);
    Table altered.
    SQL>
    SQL> insert into child values('B','4');
    insert into child values('B','4')
    ERROR at line 1:
    ORA-02291: integrity constraint (DBADMIN.FK_CHILD_PARENT) violated - parent key not found
    SQL>
    SQL> insert into child values('B',NULL);
    1 row created.
    SQL>
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

  • Primary&foreign key rerlation ship

    hi folks,
    i am going to pick material in mm03 transaction after that i selected  classification tab choose batches for class type it displays values and clisifications
    now i want to find tables which is having the relation ship (primary key and foreign key)between material number and class type
    so could plz clarify my doubt
    regards,
    sree

    Hi
    Check table DD05S.
    Award points if found useful.
    Regards
    Inder

  • Detect the fields which are primary/foreign keys for each schema's tables

    Hello everybody,
    I'd like to know if it's possible to select a field in one of the dictionary tables to identify the fields of a table which are PK or FK in this one. I'd like to do this to generate the fields that I need to put in a technical design.
    Actually I have this (if it can help you to understand what I'd like to do) :
    select table_name "Table name",
    column_name "Physical field name",
    case when data_type = 'NUMBER' then data_type || '(' || NVL(data_precision,0) || ',' || NVL(data_scale,0) || ')'
    when data_type = 'VARCHAR2' then data_type || '(' || data_length || ')'
    else data_type
    end "Datatype",
    case when nullable = 'Y' then 'FALSE'
    when nullable = 'N' then 'TRUE'
    end "Not null",
    /* Here I'd like to retrieve TRUE or FALSE if the field to display is a primary key or not and the same for foreign keys*/
    from all_tab_columns
    where table_name in (select table_name
    from all_tables
    where table_name like '%project_name%'
    and table_name not like '%TMP%');
    Thanks a lot for your help,
    Florent

    Please investigate all_constraints and all_cons_colums.
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14237/toc.htm

  • Primary / foreign key replication

    Good Day,
    Suppose  we have a Warm Standby , ASE 15.5, RS 15.6 with several databases pairs and table cross reference between these different databases, i.e:
    Pdb1 -> Stdby1
    Pdb2 -> Stdby2
    PdbN -> StdbyN
    Table T1 is at Pdb1 , table T2 is at Pdb2
    T1 has  a Pkey  , T2 has  a Fkey  to PKey on T1( for example a master / detail relation ship) 
    and so on
    Some times due to network latency (or other event)  table T2 gets replicated before than T1 and replcation stops due to primary constraint violation, even though the PK exists on T1 ( but hasn't been replicated yet).
    Q: Is there any way to ensure that T1 would get replicated first in order to avoid the error?
    Thank you
    Regards
    Jose-Miguel

    Hmmmm, doesn't work for me ... what am I missing?
    ===================================
    select @@version
    go
    Adaptive Server Enterprise/15.7/EBF 22230 SMP SP121
    sp_displaylogin
    go
    ... snip ...
    Configured Authorization:
            sa_role (default ON)
            sso_role (default ON)
            replication_role (default ON)
            mon_role (default ON)
    Locked: NO
    ... snip ...
    use tempdb
    go
    create table t1 (a int, b int)
    go
    alter table t1 add primary key (a)
    go
    create table t2 (a int references t1(a), c int)
    go
    insert t2 values (1,5)
    go
    Msg 546, Level 16, State 1:
    Server 'WLP_STAGINGREP', Line 1:
    Foreign key constraint violation occurred, dbname =  'tempdb', table name = 't2', constraint name = 't2_a_345657311'.
    Command has been aborted.
    set disable_ri_check on
    go
    insert t2 values(1,5)
    go
    Msg 546, Level 16, State 1:
    Server 'WLP_STAGINGREP', Line 1:
    Foreign key constraint violation occurred, dbname =  'tempdb', table name = 't2', constraint name = 't2_a_345657311'.
    Command has been aborted.
    insert t1 values (1,5)
    insert t2 values (1,7)
    go
    set disable_ri_check on
    go
    delete t1
    go
    Msg 547, Level 16, State 1:
    Server 'WLP_STAGINGREP', Line 1:
    Dependent foreign key constraint violation in a referential integrity constraint. dbname =  'tempdb', table name = 't1', constraint name = 't2_a_345657311'.
    Command has been aborted.
    -- and just in case the logic is reversed
    set disable_ri_check off
    go
    delete t1
    go
    Msg 547, Level 16, State 1:
    Server 'WLP_STAGINGREP', Line 1:
    Dependent foreign key constraint violation in a referential integrity constraint. dbname =  'tempdb', table name = 't1', constraint name = 't2_a_345657311'.
    Command has been aborted.
    ===================================

  • Primary - Foreign key

    hi
    oracle 10.2.0.1.0
    when there is foreign key then there should be corresponding column with either primary key / unique key constraint. Why is this rule aprt from normalization rules to make one Relational-DB
    please help
    like sample
    customer table - customer id.
    Account table - account id , customer id .
    Address table - Adress id , address line1.for sake of unique identification of an unique tuple ? is it all to sum up ?
    Edited by: 804282 on Feb 27, 2011 9:41 PM

    804282 wrote:
    hi
    oracle 10.2.0.1.0
    when there is foreign key then there should be corresponding column with either primary key / unique key constraint. Why is this rule aprt from normalization rules to make one Relational-DB
    please help
    like sample
    customer table - customer id.
    Account table - account id , customer id .
    Address table - Adress id , address line1.for sake of unique identification of an unique tuple ? is it all to sum up ?
    Edited by: 804282 on Feb 27, 2011 9:41 PMAlso to improve query performance. You usually want to put indexes on join columns.

  • Problem with primary/secondary keys in table with included structures

    Dear ABAPers,
    we have a structure which is supposed to be included in the definition of several tables.
    The problem is the following:
    depending on the application table that includes this structure, 3 or 4 fields of that structure may
    or may not be necessary to enhance the table key. As far as I know included structures can only
    completely be marked as keys. Therefore I suggested to split up the structure into two parts,
    one part with the possible candidates that may become key fields, and the rest, and of course
    a structure that unites both of these substructures. So when it comes to reusing this structure
    the developer would have the choice to select the structure with all of the fields in case no field
    is needed as additional key, or the developer would have to implement both of the substructures
    separately with the option to mark the key-part of it as key in his table.
    But unfortunetaly this suggestion of mine was refused as being too complicated and I am supposed
    to define all the fields in one flat structure and to "enhance" the primary keys (that always will exist)
    by secondary keys.
    Does anybody know how that is supposed to work without defining double indexes?
    I cannot activate a table without having primary keys defined and any unique secondary index would
    allways include all of the primary keys.
    Thanks in advance for you help
    (I'm sorry that you cannot be granted reward points for just reading the extensive problem description)
    regards
    Andreas

    Dear Rob,
    since your answer was helpful and since it was the only one I will grant you full points on that.
    Thanks again for your input. In case other developers should look this thread up being confronted
    with the same kind of problem, here is how we solved it:
    We added an artificial primary key (a number of type NUMC 8) to the table which is supposed to
    include the structure. This key alone takes care of the uniqueness of eacht entry.
    All the others fields that we want to have available for a fast direct access, including the ones
    from the included structure, are put together in a secondary index.
    best regards
    Andreas

  • CMR - Can a primary key also be a foreign key?

    Hi,
    Has anyone come across the following problem? Although I mention Jdeveloper below I believe it is a general J2EE issue!
    I have two tables
    customer
    customer_id (PK)
    individual
    customer_id (PK)
    customer_id in individual is the primary key for that table. It is also a foreign key ( related back to customer).
    If I use JDeveloper to drag in the two tables ( into a class diagraqm), I have a problem.
    JDeveloper "sees" the Individual bean foreign key mapping and generates a getCustomer() method (which returns a handle to the appropriate customer bean).
    However as it "removes" the getCustomer_id() method(which returns the actual customer_id), the primary_key reference is dropped.
    When I try and compile, JDeveloper quite rightly complains with "where is the primary key".
    Can anyone help? Do I need to make it a rule that the foreign key is not also the primary key?
    thanks in advance,
    Kevin

    Hi Kevin,
    I would not pursue this model if I was you. The only thing OC4J supports without killing yourself is to let each table has its own primary key (preferably not composed) and to make all foreign key's optional !
    We have spent months trying to make it work and we are getting little or no support from oracle, even though we are paying many euros for a partnering contract.
    greetz,
    Jurgen

  • FOREIGN KEY IS PRIMARY KEY

    Hi,
    Has anyone come across the following problem?
    I have two tables
    customer individual
    customer_id (PK) customer_id (PK)
    customer_id in individual is the primary key for that table. It is also a foreign key ( related back to customer).
    If I use JDeveloper to drag in the two tables ( into a class diagraqm), I have a problem.
    JDeveloper "sees" the Individual bean foreign key mapping and generates a getCustomer() method (which returns a handle to the appropriate customer bean).
    However as it "removes" the getCustomer_id() method(which returns the actual customer_id), the primary_key reference is dropped.
    When I try and compile, JDeveloper quite rightly complains with "where is the primary key".
    Can anyone help? Do I need to make it a rule that the foreign key is not also the primary key?
    thanks in advance,
    Kevin

    Hello,
    I am having the same problem attempting to use a foreign key as a primary key in an EJB 2.0 CMR running on WLS 6.1. If I do not set the foreign key portion of my composite key in the ejbCreate() method I get an error stating that the field cannot be null (and must be set), when I set the field in the ejbCreate I then get an Error in the ejbPostCreate stating that CMR fields cannot be set using the setXXX methods. The entity relations are as follows:
    SalesOrder <--------------------------------------->SalesOrderProduct
    SalesOrder = (orderid(PK)+orderstatus+salesrepid+contractdate+processdate)
    SalesOrderProduct = (orderid(PK/FK)+productid(PK)+qty+unitcost)
    The CMR relationship is bi-directional. The SalesOrder entity bean's ejbPostCreate() method
    invokes a helper method that attempts to create the salesOrder product entity as part of the salesorder create transaction and that's when I get the errors stated above.
    Have or anyone found out how to handle this kind of cmr using the Weblogic server (6.1) and ejb 2.0??
    Thanks,
    Darryl

  • PRIMARY KEY(MASTER)를 REFERENCE하는 FOREIGN KEY 찾는 SQL

    제품 : ORACLE SERVER
    작성날짜 : 2004-03-12
    PRIMARY KEY(MASTER)를 REFERENCE하는 FOREIGN KEY 찾는 SQL
    ========================================================
    $sqlplus sys/manager(SYS user 로 login 함)
    sql> select c.name constraint_name
    from dba_objects a,
    cdef$ b,
    con$ c
    where a.object_name = 'TABLE_NAME'
    and a.object_id = b.robj#
    and b.con# = c.con#
    /

    Hello again,
    May be I was not clear enough.
    Scenario 1: We use the master-detail form as is with the default oolbar. In this case, the user can insert the detail records one by one without needing the primary-foreign key value since this is handled by default.
    Once we save the form (commit_form), I use the pre-insert trigger to get the master block primary key generated from the sequence and since the detail block key is copied from this value, both are saved correctly and it is the end of the story.
    Scenario 2: As explained in the initial post, the user will populate the detail records one by one by clicking on the -INSERT DETAIL- button and hence has a window where he can insert the detail info and then be brought back to the master-detail form every time he enters a new detail record.
    The problem here is that I can't generate the primary key for the master block since the client has the following requirement:
    The user can always change his mind and not complete, meaning save the form, his process
    As such, the key should be generated in the last step before Commit.

Maybe you are looking for