Auto Population of foreign key

HI All
can a foreign key of a table be auto populated once the a row for the foreign key referred table has been inserted?.....
i have a common attribute for both the tables.
Please help

sorry for the double posting as my network is
experiencing problemsIf that happens, please have the courtesy to pick one thread as the main one, and provide a link to it in the other thread, so that people don't waste their time duplicating each others' answers.

Similar Messages

  • Master-Detail Forms (Populating a Foreign Key Automatically)

    Master-Detail Form
    When inserting a MD Form, the Master ID (e.g. Deptno,the Primary Key) is generated.
    How is it possible for this also to be generated in the Detail Form (as the Foreign Key)? The requirement is for the foreign key to be populated automatically.
    Any help would be much appreciated.
    Thanks.

    This item is discussed earlier in this group.
    It's solved in version 3.0.8
    Regards,
    Anna

  • Populating custom foreign key using EIM Import

    Hi,
    This is regarding a requirement wherein we are trying to populate the custom foreign key in the siebel base table using the EIM import.
    The table being used are as .
    S_CL_PTCL_LS ----> having vanilla PRDINT_ID foreing key to S_PROD_INT
    S_CL_PTCL_LSXM--> Created custom colum x_prod_id as foreing key to S_PROD_INT
    using EIM_CL_PTCL_LS ---> Created mapping for the custom foreign key field to resolve the UK cols.(NAME,BU_ID,VENDR_OU_ID)
    When we are executing the EIM import PRDINT_ID column foreing key to S_PROD_INT is getting resolved properly; however the custom column x_prod_id as foreing key to S_PROD_INT in S_CL_PTCL_LSXM is not getting resolved.
    The data for the resolution is same for both the mappings.
    Can some let me know if it is possible to do such import for custom foreign keys/this import is only possible for the vanilla foreign key refrences.
    Warm Regards,
    Ashutosh

    Hi,
    I think the custom FK may be a mistake.
    PAR_ROW_ID is the foreign key from S_CL_PTCL_LSXM to S_CL_PTCL_LS. You don’t have to create your own FK to do something that Siebel provides OOTB.
    Please check that you really need the custom FK. I don't think you do. You should simply join to S_CL_PTCL_LS and then to S_PROD_INT. This is Siebel Tools 101 but I have seen this mistake many times.
    Robert
    Robert Ponder
    Lead Architect and Director
    Ponder Pro Serve
    cell: 770.490.2767
    fax: 770.412.8259
    email: [email protected]
    web: www.ponderproserve.com
    Edited by: Robert Ponder on Dec 27, 2010 8:48 AM
    Edited by: Robert Ponder on Dec 27, 2010 8:50 AM

  • Foreign key fields not getting populated in datacontrol palette for EJB app

    Hi,
    I am quite new to ADF and EJB.I developed a jdeveloper application with JSF and EJB tiers.(I am using jdeveloper 10.1.3.5)
    For database the default HR database is used.I created the entities for the EMPLOYEES and DEPARTMENTS table.
    I also created a session bean and a data control for the session bean.
    I am having a JSF page that receives all the details of a new Employee and insert into database (i.e persistEntity)
    But the Employees constructor from the Data control palette is not populating the MANAGERID and DEPARTMENTID fields which are
    the foreign key constraints for the EMPLOYEES table and hence while trying to persist the entity
    with the auto populated fields an error message is thrown.
    If I used ADF BC instead of EJB then i could populate all the fields including MANAGERID and DEPARTMENTID.
    Is it possible to have two text fields for Manager and Department in the jsf to insert the Employee details with EJB as the Model?.
    If possible how do I bind the values of these fields to the Employees entity object in EJB.
    Kindly need your insights on this.
    Thanks,
    Guna.

    Hi,
    How are you using MANAGER_ID and DEPARTMENT_ID fields, are they exposed as Long (or some other numeric type), or did you map them on the entity, something like this
    @ManyToOne
    private Employee manager; // this by default uses the column named MANAGER_ID
    @ManyToOne
    private Department department; // this by default uses the column named DEPARTMENT_ID
    .... If you mapped them (which is the right way), when you create an employee you should set these attributes before persisting the entity, by using employee.setManager(manager) and employee.setDepartment(department). Then, the foreign keys get populated automatically by your persistence provider (Toplink).
    If you are using data controls, it is a little different process to set the department and manager, but you should take a look at this tutorial http://www.oracle.com/technology/obe/obe11jdev/ps1/ejb/ejb.html , it will hopefully answer a lot of your questions.
    Pedja

  • Auto populating application identity primary key?

    I'm sure this has been asked before but I couldn't find anything by many
    searches.
    I have some classes with int or long as their primary key. I prefer using
    application identity so the application can have direct access to the
    primary key.
    I would like to have the primary key automatically populated by Kodo from
    a sequence such that I can do:
    MyObject test = new MyObject();
    pm.makePersistent(test);
    assertTrue(test.getId() > 0);
    Is this possible in Kodo? I haven't been able to find it. I know I can do
    it with datastore identity but I would really like to avoid that.
    Thank you,
    Joel Shellman

    Hi Joel,
    before you may consider to use auto-incremented appid PK's let me tell
    some things from my own experience.
    If you have auto-incremented primary key fields you have consider that
    their values will be finally set when you commit the transaction.
    So if you access the pk fields during a transaction their values will be
    NOT set until you call explicitly KodoPersistenceManager.flush() or commit
    the transaction.
    If you use applications identity and if you have a compound PK's which one
    its fields presents a foreign key from a relation, you have to consider
    this behavior and maybe run into problems.
    I had many problems with it and finally build a wrapper around the
    sequence generator instance from KodoHelper.getSequenceHelper ().
    Greetings,
    Matthias
    Stephen Kim wrote:
    Joel, there is not, unless you are using auto-incrementing primary keys.
    You can do it in application code by calling
    KodoHelper.getSequenceHelper (). Note that you should not have this in
    an empty constructor as it may interfere with integration with JDO's
    registration system.
    Joel Shellman wrote:
    I'm sure this has been asked before but I couldn't find anything by many
    searches.
    I have some classes with int or long as their primary key. I prefer using
    application identity so the application can have direct access to the
    primary key.
    I would like to have the primary key automatically populated by Kodo from
    a sequence such that I can do:
    MyObject test = new MyObject();
    pm.makePersistent(test);
    assertTrue(test.getId() > 0);
    Is this possible in Kodo? I haven't been able to find it. I know I can do
    it with datastore identity but I would really like to avoid that.
    Thank you,
    Joel Shellman
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • 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

  • How to alter or add foreign key constr to table having child rows or data

    Hi,
    I have a table by name DEPT in which the column DEPTNO is a primary key column and have data in it for all the columns . Now I have a EMP table where in the column DEPTNO is not having any constraint including foreign key constraint too. Now i have data in the EMP table for all the columns . now i would like to add the foreign key constraint to DEPTNO column in the EMP table referencing the DEPTNO column in the DEPT table. Both the table do not have any null values .
    I need to add the foreign key without deleting the data in the EMP table.
    Please advice.
    Regards,
    Vinesh

    Hi,
    I need to add the foreign key without deleting the data in the EMP table.Foreign key constraint can have only those values which are present in the primary key of the parent table or null.
    When your tables are populated with values and then you are adding the constraint then,
    the parent table data is only present in child table or null values.
    Example
    SQL> create table emp_bkp as select * from emp;
    Table created.
    SQL> create table dept_bkp as select * from dept;
    Table created.
    SQL> alter table dept_bkp
      2  add constraint pk_deptno primary key(deptno);
    Table altered.
    SQL> select distinct deptno from emp_bkp;
        DEPTNO
            30
            20
            40
            10
    SQL> select deptno from dept_bkp;
        DEPTNO
            10
            20
            30
            40
            55
    SQL>  alter table emp_bkp
      2   add constraint fk_deptno_bkp foreign key(deptno)
      3    references dept_bkp(deptno);
    Table altered.
    SQL> alter table emp_bkp
      2  drop constraint fk_deptno_bkp;
    Table altered.
    SQL> insert into emp_bkp(empno,ename,deptno) values(142,'Fenny',90);
    1 row created.
    SQL> alter table emp_bkp
      2  add constraint fk_deptno_bkp foreign key(deptno)
      3   references dept_bkp(deptno);
    add constraint fk_deptno_bkp foreign key(deptno)
    ERROR at line 2:
    ORA-02298: cannot validate (SCOTT.FK_DEPTNO_BKP) - parent keys not found
    SQL> update emp_bkp
      2  set deptno=null
      3  where empno=142;
    1 row updated.
    SQL> alter table emp_bkp
      2  add constraint fk_deptno_bkp foreign key(deptno)
      3   references dept_bkp(deptno);
    Table altered.
    SQL> insert into dept_bkp (deptno,dname)values(90,'IT');
    1 row created.
    SQL> update emp_bkp
      2  set deptno=90
      3  where empno=142;
    1 row updated.Twinkle

  • Primary key  ID ... Foreign key iD ???

    Here is the setup. I have a database on a SQL server and have
    created a form to input data into this database (with Dreamweaver
    and CF).
    Let me start out by telling you basically how this data base
    is setup:
    3 tables:
    - tblPatients (which is the main table). Primary key is ID
    (an auto number field).
    - tblDiagnosis (which only houses an ID field and code field
    called DSMIV). The ID in the tblDiagnosis table is a foreign key
    and is linked to the tblPatients table’s ID.
    -tlkpDiagnosis just house all the possible diagnosis.
    I am able to input data into both tblPatients table and the
    tblDiagnosis table, BUT the ID (foreign key) field in the
    tblDiagnosis table is left empty thus left orphaned with no way to
    tight it back to the data in the patient table. My code is below.
    Thank you for any help you can provide me.
    PROCESS PAGE CODE:
    <cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
    <cfif IsDefined("FORM.MM_InsertRecord") AND
    FORM.MM_InsertRecord EQ "form1">
    <cfquery datasource="dsnPsychiatry">
    INSERT INTO dbo.tblPatients (NewContinuous, ResidentID,
    ResidentInitial, Age, Race, Sex, EmploymentStatus, HP, MedCheck,
    Therapy30Minute, Therapy60Minute, TherapyGroup, ECT, Inpatient,
    Outpatient, EmergencyRoom)
    VALUES (
    <cfif IsDefined("FORM.NewContinuous") AND
    #FORM.NewContinuous# NEQ "">
    <cfqueryparam value="#FORM.NewContinuous#"
    cfsqltype="cf_sql_clob" maxlength="1">
    <cfelse>
    </cfif>
    <cfif IsDefined("FORM.ResidentID") AND #FORM.ResidentID#
    NEQ "">
    <cfqueryparam value="#FORM.ResidentID#"
    cfsqltype="cf_sql_clob" maxlength="10">
    <cfelse>
    </cfif>
    <cfif IsDefined("FORM.ResidentInitial") AND
    #FORM.ResidentInitial# NEQ "">
    <cfqueryparam value="#FORM.ResidentInitial#"
    cfsqltype="cf_sql_clob" maxlength="1">
    <cfelse>
    </cfif>
    <cfif IsDefined("FORM.Age") AND #FORM.Age# NEQ "">
    <cfqueryparam value="#FORM.Age#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.Race") AND #FORM.Race# NEQ "">
    <cfqueryparam value="#FORM.Race#" cfsqltype="cf_sql_clob"
    maxlength="1">
    <cfelse>
    </cfif>
    <cfif IsDefined("FORM.Sex") AND #FORM.Sex# NEQ "">
    <cfqueryparam value="#FORM.Sex#" cfsqltype="cf_sql_clob"
    maxlength="1">
    <cfelse>
    </cfif>
    <cfif IsDefined("FORM.EmploymentStatus") AND
    #FORM.EmploymentStatus# NEQ "">
    <cfqueryparam value="#FORM.EmploymentStatus#"
    cfsqltype="cf_sql_clob" maxlength="10">
    <cfelse>
    </cfif>
    <cfif IsDefined("FORM.HP") AND #FORM.HP# NEQ "">
    <cfqueryparam value="#FORM.HP#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.MedCheck") AND #FORM.MedCheck# NEQ
    "">
    <cfqueryparam value="#FORM.MedCheck#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.Therapy30Minute") AND
    #FORM.Therapy30Minute# NEQ "">
    <cfqueryparam value="#FORM.Therapy30Minute#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.Therapy60Minute") AND
    #FORM.Therapy60Minute# NEQ "">
    <cfqueryparam value="#FORM.Therapy60Minute#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.TherapyGroup") AND
    #FORM.TherapyGroup# NEQ "">
    <cfqueryparam value="#FORM.TherapyGroup#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.ECT") AND #FORM.ECT# NEQ "">
    <cfqueryparam value="#FORM.ECT#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.Inpatient") AND #FORM.Inpatient#
    NEQ "">
    <cfqueryparam value="#FORM.Inpatient#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.Outpatient") AND #FORM.Outpatient#
    NEQ "">
    <cfqueryparam value="#FORM.Outpatient#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    <cfif IsDefined("FORM.EmergencyRoom") AND
    #FORM.EmergencyRoom# NEQ "">
    <cfqueryparam value="#FORM.EmergencyRoom#"
    cfsqltype="cf_sql_numeric">
    <cfelse>
    NULL
    </cfif>
    </cfquery>
    <cfloop list="#FORM.DSMIV#" index="diagnosis">
    <cfif IsDefined("FORM.DSMIV") AND #FORM.DSMIV# NEQ "">
    <cfquery datasource="dsnPsychiatry">
    INSERT INTO dbo.tblDiagnosis (DSMIV)
    VALUES (
    <cfqueryparam value="#diagnosis#" cfsqltype="cf_sql_clob"
    maxlength="50">
    </cfquery>
    </cfif>
    </cfloop>
    </cfif>

    Ok that didn't work. Most likely due to my lack of knowledge
    when it comes to this.
    I've been doing some research on Stored Prcedures, and
    thought it might be the answer to my problems.
    Here is the code I came up with.
    First is the Stored Procedure (on the SQL Server):
    CREATE PROCEDURE spInsertDiagnosis
    @ID integer,
    @DSMIV varchar(25)
    AS
    insert into tblDiagnosis (ID, DSMIV) values (@ID, @DSMIV)
    GO
    Second, is the CF on my process page
    <cfif IsDefined ("ID") AND #ID# NEQ "">
    <cfif IsDefined("FORM.DSMIV") AND #FORM.DSMIV# NEQ "">
    <CFSTOREDPROC procedure="dbo.spInsertDiagnosis"
    datasource="dsnPsychiatry">
    <CFPROCPARAM type="IN" dbvarname="@ID" value="#ID#"
    cfsqltype="CF_SQL_INTEGER">
    <CFPROCPARAM type="IN" dbvarname="@DSMIV" value="#DSMIV#"
    cfsqltype="CF_SQL_VARCHAR">
    </CFSTOREDPROC>
    </cfif>
    </cfif>
    NOTE: The above CF code replaced the below on my process page
    (ref to first post).
    <cfloop list="#FORM.DSMIV#" index="diagnosis">
    <cfif IsDefined("FORM.DSMIV") AND #FORM.DSMIV# NEQ "">
    <cfquery datasource="dsnPsychiatry">
    INSERT INTO dbo.tblDiagnosis (DSMIV)
    VALUES (
    <cfqueryparam value="#diagnosis#" cfsqltype="cf_sql_clob"
    maxlength="50">
    </cfquery>
    </cfif>
    </cfloop>
    PROBLEM now is, in doing this now nothing gets inserted into
    the Diagnosis table. Obviously I do not know how to correctly
    insert the stored procedure into my process page.

  • Primary Key from foreign keys

    I have a table which has 3 foreign keys, two of which form the primary key.
    I have: ID_Product, ID_Sale, ID_Buy, and also an attribute which tells if its a buy or a sale.
    So, if a sale is made, the primary key should consist of ID_Product && ID_Sale, otherwise, it's ID_Product && ID_Buy.
    Is there a way to do this in Oracle, and if there is, can you point me to where I can read about this?
    thank you in advance

    tashe,
    This is the wrong forum for you question. Try posting here:
    PL/SQL
    I will say, however, that there are advantages to keeping your primary keys apart from your data - just populating them from a sequence. Also, you may be temped to enforce this via triggers, but read the following first:
    http://tkyte.blogspot.com/2008/05/another-of-day.html
    Not that you would have a mutating table problem, but the two table solution may help you. Really think the design through.
    Regards,
    Dan

  • [JPA] Primary key = Foreign key = Failure.

    Hello:
    I've a question regarding the Java Persistence API and a DB design which I'm facing just now. I'm making JPA entities based on a DB schema which is already created. Although sometimes it's not a good idea, I'm going to use a simplified example so you can understand it easily and help me (if you want, of course).
    Let's suppose that I've a table of discs (called "disc", built into a class as "Disc.class") and another one of used discs (called "disc_used", built as "DiscUsed.class"). The first one employs a composite key formed by columns "key1" and "key2". The second one employs the same primary key (conceptually, not physically) which, at the same time, is foreign key respect to the first table.
    I've used the @EmbeddedId annotation on the first case and built a class for the composite key (called "DiscPK.class"). I've done the same task for the second table (calling it "DiscUsedPK.class"). I also have added the corresponding mappings between both classes (of type @OneToOne). This design pattern works fine when employing "Disc.class", but not "DiscUsed.class". I've came to the conclusion that it's because of using the same fields to make an @EmbeddedId and map the @OneToOne relation.
    I've been taking a deep look to the possible annotations which JPA offers, but I've not found anything useful.
    In the past I faced another problem with JPA and composite keys, which made me come to the conclusion that it was my DB design what was faulty (I was combining an auto-numerical field with others to make a composite key, which helped me to understand the logic but was absurd and against the relational logic). May it be a similar misconception on the DB design? I mean, since both tables represent different concepts (discs and used discs), each one with their own attributes (columns), Should the second table use its own auto-numerical primary key instead of re-use the foreign key? Would it be the right approach according to the relational logic?
    Obviously, modifying the original DB by hand and adding its own primary key, it works flawless. However I still need to know the truth (other-way I won't be able to sleep :P ).
    Thank you for your help and interest.

    gimbal2: I'm really sorry, but I didn't get any e-mail notification about your message :S . After having looked for help on several places on the Internet I finally decided not to employ exactly the same columns for a primary key if they were already being employed by a foreign key. The answer from javaUserMuser has also left this matter clarified to me. Thanks for your time also ;) .
    javaUserMuser: I thought that was a problem from my implementation. If it's a common case, then I guess that I did right choosing the easy "path" for one time :) . I agree with you, it's a big frustration. But since I depend on the JPA for my projects, I'll try to set my mind to avoid always this match and employ another primary key instead. Thank you a lot for your explanation :D .

  • Logical foreign key display values

    I have a schema in which the primary keys are auto generated numbers. Foreign keys exist from child tables to the primary key of the parent.
    I have figured out how to change auto generated forms to display a dropdown list of display/values to the user on insert or update instead of the meaningless number.
    What I can't figure out how to do is have the generated report show the display that I am looking for without losing the ability to edit the child record. As soon as I manipulate the query to include another table I lose the icon in the application to edit the row.
    Is it possible to keep the edit icon on the report while showing logical values instead of actual ones?
    Thanks in advance,
    Chris S.

    We'll use a football analogy because it's time for the ployoffs.
    Let's create a TEAMS table and a DIVISIONS table.
    TEAMS consists of:
    TEAM_ID NUMBER -> PK
    LOCATION VARCHAR2(35)
    TEAM_NAME VARCHAR2(35)
    and DIVISIONS consists of:
    DIVISION_ID NUMBER -> PK
    DIV_NAME VARCHAR2(35)
    Now there can't just be a link from a team to a division because they move around a bit. The Detroit Lions used to be in the NFC Central. That doesn't exist anymore and now they are in the NFC North. (Please set aside the fact that the NFC should be a part of the conferences table).
    This means that I would create a table to link the TEAM record to a DIVISION record with the season that the team became a part of the division and potentially the last season that they were in that division. This table will be called DIVISION_TEAM_XREF and looks like this:
    LINK_ID NUMBER -> PK
    DIVISION_ID NUMBER -> FK(DIVISIONS.DIVISION_ID)
    TEAM_ID NUMBER -> FK(TEAMS.TEAM_ID)
    SEASON_EFF NUMBER(4) (actually a year maybe a VARCHAR2 would be better)
    SEASON_TERM NUMBER(4) (nullable)
    Now I created all of that through HTML DB with foreign keys from the XREF table to the teams and divisions tables. Then I create an application throught the application builder. I choose report and form and the application type like the demo. for each of the three tables. Choose a theme and walah there is an application with all three tables. If I add data to TEAMS or DIVISIONS I can see them in the report page that is created and there is an icon to the left of each row which when clicked will allow me to edit the row.
    The problem comes with my XREF table. The creation screen is just a form which expects me to know the auto generated number that was created for my division and team. I have figured out how to change this in the application builder so that it is a drop down list built from a query of the respective table.
    Once I create a record I can see it in the report page for the XREF table. This page has the option to edit the record but the values on the screen are the auto generated numbers that don't mean anything to a user. When I change this page to use display values from the parent tables I lose the edit icon.
    Here is the original query that the application builder used:
    select
    "LINK_ID",
    "DIVISION_ID",
    "TEAM_ID",
    "SEASON_EFF",
    "SEASON_TERM"
    from "DIVISION_TEAM_XREF"
    and here is what I would like to change it to:
    select
    XREF.LINK_ID "LINK_ID",
    DIV.DIV_NAME "DIVISION",
    TEAM.TEAM_NAME "TEAM",
    XREF.SEASON_EFF "SEASON_EFF",
    XREF.SEASON_TERM "SEASON_TERM"
    from "DIVISION_TEAM_XREF" XREF, DIVISIONS DIV, TEAMS TEAM
    where XREF.DIVISION_ID = DIV.DIVISION_ID
    and XREF.TEAM_ID = TEAM.TEAM_ID
    Sorry for the long post. Hope that clarifies.
    Chris S.

  • Populate the foreign key automatically

    HI All!
    I have a form in which there are two data blocks One is emp_master and other is salary_details.I have a foreign key salary_code in Emp_master and similarly Salary_code as primary key in salary details.I have used two list item in place of Emp_id and Salary_code.I want that when I select the emp_id as 10 from the list automatically salary_code list item should get populated by 1 item in the list item.Similary the rest should follow .Please someone look into this matter it would be a gr8t help to me.
    Thanks

    Abha,
    I would not use list items for this. Instead, use a multi-record text box with a scroll bar. It looks and behaves like a t-list, but is much easier to code and manage.
    Use the datablock wizard to create the master-detail relationship. When you use the wizard, all the code will be generated for you. Then use the layout wizard, and display multiple records with scroll bars.
    BTW, it is customary to have the primary key in the master, and the foreign key in the details. In your case it is backwards.
    Also see
    http://www.oracle.com/technology/obe/obe_as_10g/bi/forms/formsmasterdetailobe.htm

  • Regarding foreign keys

    Hi
    i have got tables tab1. now tab1 has composite primary key
    col1and col2. for col1 there are many values of col2. thus many records in tab1 can have same value for col1 but unique value for col2 for corresponding values for col1. see below
    col1 col2
    1 1
    1 2
    1 3
    2 1
    2 2
    3 1
    4 1
    4 2
    4 3
    now i have designed a form on this table.
    now my requirement is that i have two items for this two columns and they are pop up lov's. now my requirement is that when i select a value for item col1 thru its LOV then LOV for col2 should be populated as per the value of col1.
    For example if col1 value is 1 than LOV for col2 should contain values 1,2,3,4.
    i tried to do it thru computation but the computation has options before after header, footer, region.
    Also cannot do it thru processes.
    Please relp urgently.
    Thanks
    Ameya

    Hi and welcome to the forum.
    Now , can I define a foreign key at column level in oracle?please help.Yes, you can. http://en.wikipedia.org/wiki/Foreign_key
    Oracle Documentation is your friend, explore it and search it:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_constraints.htm#sthref744
    Oracle documentation home = http://tahiti.oracle.com, from there you can search on your keywords of specific interest easily.
    Make sure to choose to drilldown on your own database version.

  • How to insert value for composed foreign key?

    My problem when I update or insert to table Ffclient which has link 1-1 with other table ClientLoan by composes primary key loanId and clienId (break table). I auto mapping by Jdeveloper 10g version 10.1.2. In FfClient table has two fields compose foreign key of ClientLoan as loanId and clienId not nullable. In toplink object Ffclient it only has one reference ClientLoan object by clientLoan field, not has two fields loanId and clienId . When I insert or update to database, I can't set value for these two fields direct so I have created new ClientLoan object and set value for composed primary key loanId and clienId, after that set it to object Ffclient. But when I update or insert to database it occurs exception about insert null for two not nullable fields: loanId and clienId.
    Any one has error as mime? Any one help me correct my error.
    Thanks in advance.
    Mapping is:
    ….
    <database-mapping>
    <attribute-name>ffclientCollection</attribute-name>
    <read-only>false</read-only>
    <get-method-name>getFfclientCollection</get-method-name>
    <set-method-name>setFfclientCollection</set-method-name>
    <reference-class>uk.co.lsb.elb.toplink.Ffclient</reference-class>
    <relationship-partner-attribute-name>clientLoan</relationship-partner-attribute-name>
    <is-private-owned>false</is-private-owned>
    <uses-batch-reading>false</uses-batch-reading>
    <indirection-policy>
    <mapping-indirection-policy>
    <type>oracle.toplink.internal.indirection.TransparentIndirectionPolicy</type>
    </mapping-indirection-policy>
    </indirection-policy>
    <container-policy>
    <mapping-container-policy>
    <container-class>oracle.toplink.indirection.IndirectList</container-class>
    <type>oracle.toplink.internal.queryframework.ListContainerPolicy</type>
    </mapping-container-policy>
    </container-policy>
    <source-key-fields>
    <field>LSB.CLIENT_LOAN.CLIENT_ID</field>
    <field>LSB.CLIENT_LOAN.LOAN_ID</field>
    </source-key-fields>
    <target-foreign-key-fields>
    <field>LSB.FFCLIENT.CLIENT_ID</field>
    <field>LSB.FFCLIENT.LOAN_ID</field>
    </target-foreign-key-fields>
    <type>oracle.toplink.mappings.OneToManyMapping</type>
    </database-mapping>
    …..
    <database-mapping>
    <attribute-name>clientLoan</attribute-name>
    <read-only>false</read-only>
    <reference-class>uk.co.lsb.elb.toplink.ClientLoan</reference-class>
    <relationship-partner-attribute-name>ffclientCollection</relationship-partner-attribute-name>
    <is-private-owned>false</is-private-owned>
    <uses-batch-reading>false</uses-batch-reading>
    <indirection-policy>
    <mapping-indirection-policy>
    <type>oracle.toplink.internal.indirection.BasicIndirectionPolicy</type>
    </mapping-indirection-policy>
    </indirection-policy>
    <uses-joining>false</uses-joining>
    <foreign-key-fields>
    <field>LSB.FFCLIENT.CLIENT_ID</field>
    <field>LSB.FFCLIENT.LOAN_ID</field>
    </foreign-key-fields>
    <source-to-target-key-field-associations>
    <association>
    <association-key>LSB.FFCLIENT.LOAN_ID</association-key>
    <association-value>LSB.CLIENT_LOAN.LOAN_ID</association-value>
    </association>
    <association>
    <association-key>LSB.FFCLIENT.CLIENT_ID</association-key>
    <association-value>LSB.CLIENT_LOAN.CLIENT_ID</association-value>
    </association>
    </source-to-target-key-field-associations>
    <type>oracle.toplink.mappings.OneToOneMapping</type>
    </database-mapping>

    Yes, many thanks for you reply.
    My project has many layer (include DAO + EJB + BO + WEB).
    Toplink objects which are auto created by TopLink has only using in DAO and EJB layer, then toplink objects are transfer to Bean objects (valueObject) which are contain primitive java type as int, long, double... not java wrapper object as Integer, Long, Double... Bean objects are using from EJB to WEB layer. So when set value to bean object from toplink object I sometime don't set all reference toplink object to reference object of bean (although bean has references bean object as toplink object) because there are too big. So when I update data from WEB layer to EJB layer, before update to database, I must get fill all data for foreign key of update object by create new reference toplink object, add reference_id to this object and set it to update object. I waste a lot of time, its very handwork and tire. Are you has any solution about this problem?
    Thank in advanced.
    ThangNQ

  • ADF Toplink Create Row with foreign key

    Hello,
    I'd like to create a new row in a table that has a required one-to-one mapping relationship (foreign key). I've created an edit form by dragging the return node of a readQuery. The columns holding foreign key values aren't added to the page(because of 1-1 relationship) and when I commit the changes errors are raised.
    How do I pass the foreign key to the ADF Toplink framwork to include in the insert statement.

    TopLink's persistence model is based around relationships, which represent FKs. To have these FKs properly populated you need to create the corresponding object relationships.
    To do this you need to create a data action that will invoke a method on your class passing in the object you want to create the relationship with. There is currently an issue where ADF will not allow you to easily drop a set method onto an action. You will need to create a method on your bean that does not start with 'set'.
    In the demos I have done I have added a method like 'populateAddress(Address)' that internally calls the set method. This populate method will show up on the data control palette and you can then drop it on the action in your page flow.
    One additional tip: To access the object you want to pass in you will need to extend the default expression that reflects the current selected row in the iterator to have '.dataProvider' appended. This accesses the persistent object within row container.
    If you are still struggling please contact me through the email address in my forum profile.
    Doug

Maybe you are looking for

  • SSO to third party in EP 7.0 (SP-21)

    Folks, Could you please advise if we can do SSO to third party vendor using SAML/SAP logon Ticket in EP 7.0 (SP-21). Let me explain a bit: We have EP 7.0 (SP-21), after initial logon to portal we can access backend SAP ECC6/BI applications (WebDynpro

  • (jdeveloper11g,MacOSX,EJB) access to EJB in jdevdeloper but not from jar

    hello, I have created an application with an EJB which contains only one method : sayHello, which returns "hello" as a string. I have also created another project in the same application, and the project is a swing project with one button; when you c

  • Standard Batch Input Programs for Profit Center Creation

    Dear all; I am in 4.0B version that doesnt have BAPI_PROFITCENTER_CREATE. Writing a BDC for this would be complicated as my data is compiled in a different way. Are there any Standard Batch Input Programs for Profit Center Creation ?

  • Checking daylight savigns time patch

    I have to make a 10.1.0.3 oracle home to migrate a database that i am not allowed to upgrade. If I remember correctly from when we all had to apply the daylight savings time patch, there is a query to check to see if this is applied correctly. I can'

  • Tcode for Analyze application log

    Hello BW Experts, What is the transaction code for analyze application log. I am accessing it in this way: Ods > manage > activation > log > application log Thanks, BWer