Update primary key

Hi
I am using weblogic 7.0 and ejb 2.0
I have a requirement where i would want to update my primary key. If i understand right , In ejb you are not allowed to update one of the primary key column of composite primary key.
Now if i have to update this what are the work arounds. Aslo say if i update that row through stored proc, will my ejb state in cache be in sync with latest data. Is ejb load called for sure beofre any method is called on bean.
Please give me some inputs on this
Thanks

Your problem lies within your database (datasource)structure. You need to have two primary keys for that particular entity. The first primay key is internal meaning it is the true key for any specific record in the table. The second "primary key" is external meaning it is not truely a primary key with regards to the formal contstraints of your database. Instead, this is the key your users will see. It is the responsibilty of the application layer to ensure that the external id is unique. This way, you always have a lasting primary key (the internal key), yet your users can change their "primary key" whenever they like.
As an example, I'm writing a J2EE application that provides our clients with a unique ID to access their records. My table definition would look something like:
CREATE TABLE Client (
clientId BIGINT AUTO_INCREMENT NOT NULL,
externalClientId VARCHAR(15) UNIQUE NOT NULL,
... another field,
... another field,
CONSTRAINT pk_foo PRIMARY KEY (clientId)
The unique constraint isn't really necessary because the application layer should check for this, but it's a good safety precaution.
On the application side, you would only expose the 'externalClientId' to the clients. This might force you to use BMP, but it keeps the user from ever changing the true Id and is fairly clean.
Hope this helps.

Similar Messages

  • Update primary key in replication environment.

    Hello all,
    I would appreciate, if you could answer for my question.
    I am using oracle9i advanced asynchronous replication. What would be the issue if we update the primary key. Is it going to create any problem ?. What is the drawback on updating Primary key.
    Thanks
    Govind

    Are you using DDL propagartion?
    You should not have any problems if you have unconditional supplement logging for all columns.
    But, probably it is good idea to do it in this way:
    1 stop capture
    2 change session tag
    3. change table defenition on both sides
    4. enable capture.
    5. perform capture checkpoint right after step 4.
    Regards,
    Sergey

  • Update primary key/delete and reinsert records

    Hi, I have been told to update some fields. The database is new to me, and now I see the field is the primary key (and it has child tables with that as foreign key). The person who told me isn't reachable until next week...
    ...wasn't a bad idea to update pk's? I see it's possible, deferring constraints...
    update primary key
    Re: Update Primary Key
    ...but it's better/safer the script deletes and later re-insert the records, right?
    Thanks

    Always is better be able to undo any change .
    But ¡, why would you update pk's? it's possible but you colud find few problems like:
    - many levels of foreign keys exists.
    - not validate pk
    Look at:
    Re: Novalidate primary key

  • Tabular Form Page - Insert and Update Primary Key

    Hi -
    I am creating a Tabular Form page which will display 2 columns:
    CODE (Text Field), DESCRIPTION(Field)
    The *'CODE'* is a primary key to the table/view and *'DESCRIPTION'* is the corresponding detail information for the *'CODE'*.
    I am trying to create an updateable report on this page which will show these columns and when a user wants to add a new row,they should be able to add a new row with CODE='somecode' and DESCRIPTION='description' but shouldn't be able to update (but should be displayed) the *'CODE'* value once inserted into the table or view.
    Is there a way to do that? Please share your expertise.
    Thanks,
    -Seenu

    I't a bit unclear what you want.
    In your first post it seems that you don't want the user to change the PK.
    In your second post the user can change the PK, but you get a db error.
    Anyway, I guess you don't want the user to change the PK.
    I have a few support tables, which are the source for some LOV's.
    For those I also add records with a manual assigned PK, rather then via a sequence, just to improve consistency across applications.
    The data is protected by foreign keys to the main tables.
    You could further add a trigger to your table which throws an error the moment it detects a change on your PK.

  • How to update primary key column

    Hi,
    Can you suggest me best workaround/algorithm for below task:
    (Oracle 10g, Solaris OS.)
    Situation:
    Table P has primary key column "Code", child tables F1, F2, ..., F15 reference with foreign key column "P_Code" column "P.Code", and we don't know which of the child tables has data for particular "P.Code" value.
    Task:
    Change "P.Code" value from 100 to 200. So that result would be that record P[Code = 100] should be updated as:
    update P set
    Code = 200
    where Code = 100;And child tables column "P_Code" should be updated as:
    update F1, F2, .., F15 set
    P_code = 200
    where P_code = 100;The best solution would be that one very easily can repeat that task.
    Edited by: CharlesRoos on 28.12.2010 12:10

    If you are looking for reusable and repetitive solution, then may be...
    SQL> CREATE TABLE p (p_code NUMBER PRIMARY KEY);
    Table created.
    SQL> INSERT INTO p VALUES(100);
    1 row created.
    SQL> INSERT INTO p VALUES(300);
    1 row created.
    SQL> INSERT INTO p VALUES(500);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> CREATE TABLE F1 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> CREATE TABLE F2 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> CREATE TABLE F3 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> INSERT INTO F1 VALUES(100);
    1 row created.
    SQL> INSERT INTO F3 VALUES(100);
    1 row created.
    SQL> INSERT INTO F2 VALUES(500);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> CREATE OR REPLACE PROCEDURE update_child_parent(pi_p_code_old NUMBER,
      2                                                  pi_p_code_new NUMBER) IS
      3    CURSOR table_to_update IS
      4      SELECT table_name,
      5             to_number(extractvalue(xmltype(DBMS_XMLGEN.getxml('SELECT count(*) c FROM ' ||
      6                                                               table_name ||
      7                                                               ' WHERE p_code=' ||
      8                                                               pi_p_code_old)),
      9                                    '/ROWSET/ROW/C')) cnt
    10        FROM user_tables
    11       WHERE table_name IN ('F1', 'F2', 'F3');
    12 
    13  BEGIN
    14    EXECUTE IMMEDIATE 'ALTER TABLE p DISABLE PRIMARY KEY CASCADE';
    15    UPDATE p SET p_code = pi_p_code_new WHERE p_code = pi_p_code_old;
    16    FOR i IN table_to_update LOOP
    17      IF i.cnt > 0 THEN
    18        EXECUTE IMMEDIATE 'UPDATE ' || i.table_name || ' SET p_code=' ||
    19                          pi_p_code_new || ' WHERE p_code=' || pi_p_code_old;
    20      END IF;
    21    END LOOP;
    22    EXECUTE IMMEDIATE 'ALTER TABLE p ENABLE VALIDATE PRIMARY KEY';
    23  END update_child_parent;
    24  /
    Procedure created.
    SQL> EXECUTE update_child_parent(100,200);
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM p;
        P_CODE
           200
           300
           500
    SQL> SELECT * FROM F1;
        P_CODE
           200
    SQL> SELECT * FROM F2;
        P_CODE
           500
    SQL> SELECT * FROM F3;
        P_CODE
           200
    SQL> INSERT INTO p VALUES(300);
    INSERT INTO p VALUES(300)
    ERROR at line 1:
    ORA-00001: unique constraint (HR.SYS_C005931) violated
    SQL> EXECUTE update_child_parent(500,900);
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM p;
        P_CODE
           200
           300
           900
    SQL>  SELECT * FROM F2;
        P_CODE
           900
    SQL>

  • Who can I update primary key field in master block

    Hi,
    I want to update the primary key field in master block when there are some records are present in detail block, when I edit the primary key filed there is an error FRM-40509 unable to update record. The primary key is also referred by the detail table.
    So kindly give me the solution who can I update the primary key in master block when there is child records exists in detail block?.
    Best regard,
    shahzad

    pls tell us a little more about, why you want to update a PK in a master block.
    I haven't done that my whole time. Maybe you need something different.
    The problem is, that your child-data references to the master-pk, so there is the point you have to go deep into the codings. But better don't do it. Tell us first why. I think there are other solutions for that.
    try it
    Gerd

  • Update primary key that’s also a foreign key in another table

    Hi Developers,
    I need to update the primary key for a record but it's also the foreign key in another table.
    Example,
    Table 1 Details
    Name : Parent_Table
    Columns : ID, Name, Age
    Primary Key : ID
    Table 2 Details
    Name : Child_Table
    Columns : ID, Parent_ID, Name, Age
    Primary Key : ID
    Foreign Key : Parent_ID (Primary Key in Parent_Table)
    Parent_Table
    ID Name Age
    1001 Sam 26
    1002 George 25
    Child_Table
    ID Parent_ID Name Age
    1010 1001 Sam 26
    1020 1002 George 25
    Now I want to update ID (1001) in Parent_table as 2001 and also, I want to update Parent_ID (1001) in Child_Table as 2001.
    How we will write the java code to update these columns.
    Thanks in advance.

    dcminter wrote:
    If you're looking at changing the primary keys in your data then there's probably something wrong with your data structure.Depends how you feel about business primary keys versus surrogates. Personally I prefer the latter so I'm with you in theory. In practice, however, a DB that uses a business PK may well find that it's a legitimate use case to change the key value (but then that's why I like surrogates in the first place!)Primary keys should not have meaning.

  • Updating primary key

    HI ,
    I want to update the primary (DATBI) key of SAP table a017 with new value. I am using update statement and giving all the primary keys for identifying the record, but lasting in short dump.
    any pointers on how this can be done?
    Regards
    saurabh.

    hi
    chk this
    <b>You cannot change the primary key when you UPDATE a table for which a synchronous matchcode is defined.</b>
    another eason might b the CLIENT SPECIFIC condition needed
    UPDATE sflight <b>CLIENT SPECIFIED</b>
                   SET   seatsocc = seatsocc + 3
                   WHERE mandt    = '002'  AND
                         carrid   = 'LH'   AND
                         connid   = '0400' AND
                         fldate   = '20010228'.

  • Updating Primary Key Records and Related FK dependencies

    1) How can I found out the name of all the tables that are using my primary key as foreign keys? The primary key is a varchar & used in many other tables. Now the PK records must be changed per client request, so it will obviously affect all my dependent tables.
    2) What is the most efficient PL/SQL script to perform this procedure?
    Any suggestions will be helpful.
    For testing I think I'd like a list of all the tables followed by a list of all the records affected. This report should display the PK record & all dependency records requiring an update. Is this reasonable?

    user10998542 wrote:
    1) How can I found out the name of all the tables that are using my primary key as foreign keys? The primary key is a varchar & used in many other tables. Now the PK records must be changed per client request, so it will obviously affect all my dependent tables. Check out the USER_CONSTRAINTS view. You could do something like this:
    SELECT     UC.OWNER
    ,     UC.TABLE_NAME
    ,     UC.R_OWNER
    ,     RUC.TABLE_NAME
    ,     UC.R_CONSTRAINT_NAME
    ,     RUC.CONSTRAINT_TYPE
    FROM     USER_CONSTRAINTS UC
    ,     USER_CONSTRAINTS RUC
    WHERE     UC.R_OWNER          = RUC.OWNER
    AND     UC.R_CONSTRAINT_NAME     = RUC.CONSTRAINT_NAME
    AND     UC.CONSTRAINT_TYPE     = 'R'If you need column names you can use the USER_CONS_COLUMNS view as well.
    2) What is the most efficient PL/SQL script to perform this procedure?
    Any suggestions will be helpful.[Tom Kyte: Update Cascade Package|http://tkyte.blogspot.com/2009/10/httpasktomoraclecomtkyteupdatecascade.html]

  • Updating Primary key while creating entries

    Hi All,
    I have a requirement to update a primary key while the entry is being created in the database table.
    The program uses the INSERT statement to create entries but the primary key is unknown at that time. I want to create this primary key value and update that record before being saved in the database.
    Is there a place where i can write this code which gets called while INSERT/UPDATE statements.
    Request you urgent help.
    Thanks in advance

    Hello Archana,
    As per my understanding providing BADI implementation is one of the better options you have.
    Firstly you have to find out the standard BADI Definition provided by SAP for your functionality. You can search the same in the transaction <b>SE18</b>.
    Your BADI definition will have predefined interface methods
    (like BEFORE_SAVE, AFTER_SAVE, BEFORE_UPDATE, AFTER_UPDATE ... )
    with necessary parameters(parameter types: IMPORTING/EXPORTING/CHANGING/RETURNING). Mind you, you can't add your own methods/parameters to these standard BADI definitions.
    Now you can create your own BADI implementation(ie., you can write you code in the one of the predefined methods you have) for the standard BADI definition. For that in your BADI Definition screen go to <i>Implementation</i> in Menu bar and click on <i>Create</i>.
    I hope you will definitely have <b>Primary Key</b> as importing parameter so you can write your code logic by using this primary key in one of the methods you have based on your requirement
    <b>@</b> Please take Backend expert help in your team for finding out BADI Definition Name & for also BADI Implementation Code if you are not sure about BADI concept.
    I hope this answers your question, If YES,  !!! REWARD POINTS !!!
    Regards, Srikanth

  • Updating primary key with jdbc

    Trying to update a primary key with:
    public static void updateTAXID(String coid,String accountnumber,String oldTAXID,String fundname,String newTAXID){ Properties props = TradeHelper.loadProperties(); Connection conn = null; PreparedStatement st = null; String sql ="update FinancialAccount set taxid=? " + "where dealernumber=? and " + "taxid=? and " + "fundname=? and " + "accountnumber=?"; try{ Class.forName(props.getProperty("driver")); conn = DriverManager.getConnection(props.getProperty("brokerageurl"), props.getProperty("user"),props.getProperty("password")); st = conn.prepareStatement(sql); st.setString(1, newTAXID); st.setString(2, coid); st.setString(3, oldTAXID); st.setString(4, fundname); st.setString(5, accountnumber); st.executeUpdate(); System.out.println("Update: new tx:"+newTAXID+":"+"Ol tx: "+oldTAXID+" act:"+accountnumber); conn.close(); st.close(); }catch(Exception e){ e.printStackTrace(); } }
    I keep getting this error:
    com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '02673025561-QA-SLFCA-' for key 'PRIMARY'         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)         at com.mysql.jdbc.PreparedStatement.exe
    Am I not able to update a single field of a composit key with jdbc? Whay is my update failing telling that there is a duplicate when I am trying to update?

    iketurner wrote:
    I keep getting this error:
    com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '02673025561-QA-SLFCA-' for key 'PRIMARY'
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
    at com.mysql.jdbc.PreparedStatement.exeAm I not able to update a single field of a composit key with jdbc? Whay is my update failing telling that there is a duplicate when I am trying to update?If you take the error message at its word then the problem is not that you are not permitted to update a primary key but that the values you are trying to use is already in use.
    I'll leave it you DBA and/or Data Modeler/Architech to decide if it is a good idea to update the value or not.

  • Updating primary key problem

    Here is my scenario:
    I have inserted 5 rows in mobile client with primary key 1, 2, 3, 4,5
    Then deleted 3rd row and updated the primary key for 4th and 5th row to make the primary key sequential.
    But when I sync, I get conflict error with DML Operation update
    Does oracle lite support primary key update or primary key reshuffle?
    Thanks

    Hi,
    can you apply this one-off patch 7337669 Oracle Database Lite: Patch
    CONSOLIDATED ONEOFF FOR CUSTOMER BUGS TILL AUG 19 2008 10.3.0.1.0 19-AUG-2008
    and tell me if you are still able to reproduce this behavior?
    The Patch is available on metakink.oracle.com
    Regards.
    Marc

  • Update primary key with a tabular form based on a select list for each row

    Hello!
    I've two tables: Table1 with only one column (primary key) is a foreign key for table2.column1 (primary key). There is also a second primary key column in table2.
    Now I want to change the primary key values in table2.column1 with a tabular form (MRU) based on a select list (LOV based on table1.column1) for each row.
    The user should be able to choose for every row a new value from the select list to change the old primary key value at this position.
    How can I do this with ApEx?
    I've the tabular form and so on, but at the moment I get the following error:
    "Error in mru internal routine: ORA-20001: Fehler in MRU: row= 1, ORA-20001: ORA-20001: Die aktuelle Version der Daten in der Datenbank wurde geändert, seit der Benutzer einen Update-Prozess eingeleitet hat. ..."
    Thank you for your support!
    Kay

    Hello!
    I've two tables: Table1 with only one column (primary key) is a foreign key for table2.column1 (primary key). There is also a second primary key column in table2.
    Now I want to change the primary key values in table2.column1 with a tabular form (MRU) based on a select list (LOV based on table1.column1) for each row.
    The user should be able to choose for every row a new value from the select list to change the old primary key value at this position.
    How can I do this with ApEx?
    I've the tabular form and so on, but at the moment I get the following error:
    "Error in mru internal routine: ORA-20001: Fehler in MRU: row= 1, ORA-20001: ORA-20001: Die aktuelle Version der Daten in der Datenbank wurde geändert, seit der Benutzer einen Update-Prozess eingeleitet hat. ..."
    Thank you for your support!
    Kay

  • Does anyone know a way of making primary keys updatable in tabular forms

    Is there a way i can make my primary key updatable in a tabular form.
    I have two tables one called proposal details and one called student current details. Bascially you select one of your proposal details to become your current project this is done via the proposal id. The problem is that i cannot make this field editable in a tabular form. Does anyone know how i could make this primary key updatable?

    Hi Dan,
    One suggestion, perhaps, would be to base the tabular form on a View rather than directly off of the table. The view could include two instances of the proposal id field - the actual field and a second field called, say, PROPOSAL_ID_EDITABLE. You can then use an INSTEAD OF trigger on the view to update the actual table data with the value entered/selected in this second field.
    The reason why Apex will stop you updating primary keys is that it needs to be able to use these to get back to the original record to apply any changes. If you use a view instead, ensure that the primary key fields are not editable but allow the user to change a dummy field instead, the pk fields are available for Apex to get back to the data but the trigger will change the value instead.
    Regards
    Andy

  • Update on primary key column

    Is it possible to update primary key column data by using MRU, i tried using the same but i encountered "mru internal routine error: ORA 20001" everytime i update.
    Or is there any workaround/suggestion

    Is it possible to update primary key column data by
    using MRU, i tried using the same but i encountered
    "mru internal routine error: ORA 20001" everytime i
    update.
    Or is there any workaround/suggestionTwo things.. One, what is your name, we are friendly group of folks here and would prefer to call you by name.
    Secondly, it is a preferred idea NOT to touch the generated primary key. Why would you need to update that value?
    Can you explain further what it is you are trying to do?
    Thanks!
    Tony Miller
    UTMB/EHN

Maybe you are looking for

  • IdM 7 and SSO for legacy applications

    Dear experts, Per SAP NetWeaver 7 documentation new approach allows SSO for any legacy applications without a need for a 3rd party IdM solution. Could someone explain how this is handled? Does evary non-SAP application need to become aware of SAP IdM

  • Error 2755 when trying to install itunes on my laptop please help

    error 2755 when trying to install itunes on my laptop please help the installation process gets so far then the error 2755 appears saying that it cannot be installed

  • Best practice to secure database during patching/upgrade-Vault disabled

    I have a highly confidential system and to protect the data in the DB, I intend to use Oracle Vault. In my company, we have centralized services and therefore, the oracle Unix owner and sysdba are owned by this group, not the application dba that "kn

  • Set text on status bar

    Hi all. I need help with Text on status bar. It was working well with IE6. here is the link http://www.aubryaubry.com/index.htm thank you

  • ERPI 11.1.2.4 and odi agent java ee

    HI, I have installed EPM system 11.1.2.4 now i want to set odi agent. In previous version i have to install odi and create agents but in this version i got a preinstalled ODI and precreated ODI agent. I have few queries related to odi agents: 1 - if