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>

Similar Messages

  • How to modify primary key column?

    I want to modify one primary key column, But TT reported error.
    How do I modify primary key column? Thanks first.

    In TimesTen, the values in primary key columns cannot be updated (except for the trivial case where you update the value to the same value as it currently has). If you want to change the values stored in primary key columns the application must insert a new row with the new key values (and of course values for the other columns) and then delete the old row.
    Chris

  • How to know primary key column name form a table name in sql query

    Suppose I only know the table name. How to get its primary key column name from the table name?
    Thanks

    Views don't have primary keys though their underlying tables might. You'd need to pick apart the view to determine where it's columns are coming from.
    You can select the text of the view in question from user_views.

  • 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

  • JPA: Attr ... mapped to a primary key column in the DB. Update not allowed.

    Let me just say that I posted a bug report for this here:
    https://glassfish.dev.java.net/issues/show_bug.cgi?id=3937
    But I'm also posting the info here, so that people who search on this forum may get some help:
    TopLink (both Essentials and 11g) has a problem with flushing entities
    containing a self-reference relationship. When flushing, the following exception
    occurs:
    Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.1 (Build b14-fcs
    (12/17/2007))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: The attribute [id] of class [test.jpa.entities.Person] is
    mapped to a primary key column in the database. Updates are not allowed.
    No manual updates have been made to ANY primary key.
    What I'm doing is:
    1. I instantiate a new entity.
    2. I start a transaction
    3. I persist the new entity.
    4. I read an existing entity from the DB.
    5. I let the existing entity point to the new entity via the self-reference
    relationship.
    6. I flush the persistence context.
    7. I issue commit(), and the exception occurs. (I have provided the stack traces for various versions of TopLink below.)
    This is a clear bug.
    Here are some additional observations:
    1. Reproduced on the following versions of TopLink:
    1.1. Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))
    1.2. Oracle TopLink Essentials - 2.1 (Build b14-fcs (12/17/2007))
    1.3. Oracle TopLink - 11g Technology Preview 3 (11.1.1.0.0) (Build 071214)
    2. Reproducible both on Java SE and Java EE. (I tested on Oracle Application Server)
    3. Reproducible with and without class weaving
    4. Reproducible regardless of whether the JPA annotations are on fields or on
    methods
    5. Reproducible regardless of whether "cascade={CascadeType.PERSIST}" is used or
    not.
    6. Reproducible regardless of the fetch type of the self-reference relationship
    (EAGER or LAZY).
    Also:
    1. Without flushing, the bug doesn't occur. That is, if I commit without
    flushing, it works.
    2. Without setting the self-reference relationship, the bug doesn't occur.
    This is an issue that appears when using BOTH self-reference relationship AND
    flushing.
    Best regards,
    Bisser
    The message was edited by bisser:
    Added info that the exception occurs "when I issue commit()" on step 7.

    I'm extremely surprised that you couldn't reproduce the error. It's reproduced each time when I run the Test Scenario that I described above.
    You could download a sample Eclipse project that reproduces the error from here: https://glassfish.dev.java.net/issues/show_bug.cgi?id=3937
    For the log below I used TopLink, version: Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007)).
    Could you, please, tell me what version you use and I will try the Test Case on it.
    Here's the FINEST log:
    [TopLink Finest]: 2008.01.09 07:35:58.094--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.weaving; value=false
    [TopLink Finest]: 2008.01.09 07:35:59.312--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.orm.throw.exceptions; default value=true
    [TopLink Finer]: 2008.01.09 07:35:59.312--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--Searching for default mapping file in file:/D:/dev/bull/jpa_pk_bug/bin/
    [TopLink Config]: 2008.01.09 07:35:59.547--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The alias name for the entity class [class test.jpa.entities.Person] is being defaulted to: Person.
    [TopLink Config]: 2008.01.09 07:35:59.594--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The column name for element [private java.lang.Long test.jpa.entities.Person.id] is being defaulted to: ID.
    [TopLink Config]: 2008.01.09 07:35:59.609--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The column name for element [private java.lang.String test.jpa.entities.Person.name] is being defaulted to: NAME.
    [TopLink Config]: 2008.01.09 07:35:59.641--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The target entity (reference) class for the many to one mapping element [test.jpa.entities.Person test.jpa.entities.Person.mgr] is being defaulted to: class test.jpa.entities.Person.
    [TopLink Config]: 2008.01.09 07:35:59.703--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--The primary key column name for the mapping element [test.jpa.entities.Person test.jpa.entities.Person.mgr] is being defaulted to: ID.
    [TopLink Finest]: 2008.01.09 07:35:59.703--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--end predeploying Persistence Unit Test; state Predeployed; factoryCount 0
    [TopLink Finer]: 2008.01.09 07:35:59.703--Thread(Thread[Main Thread,5,main])--cmp_init_transformer_is_null
    [TopLink Finest]: 2008.01.09 07:35:59.703--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--begin predeploying Persistence Unit Test; state Predeployed; factoryCount 0
    [TopLink Finest]: 2008.01.09 07:35:59.703--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--end predeploying Persistence Unit Test; state Predeployed; factoryCount 1
    [TopLink Finest]: 2008.01.09 07:35:59.719--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--begin deploying Persistence Unit Test; state Predeployed; factoryCount 1
    [TopLink Finest]: 2008.01.09 07:35:59.734--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.logging.level; value=FINEST; translated value=FINEST
    [TopLink Finest]: 2008.01.09 07:35:59.734--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.logging.level; value=FINEST; translated value=FINEST
    [TopLink Finest]: 2008.01.09 07:35:59.750--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.jdbc.user; value=rms
    [TopLink Finest]: 2008.01.09 07:35:59.750--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.jdbc.password; value=xxxxxx
    [TopLink Finest]: 2008.01.09 07:36:00.766--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.target-database; value=Oracle; translated value=oracle.toplink.essentials.platform.database.oracle.OraclePlatform
    [TopLink Finest]: 2008.01.09 07:36:00.781--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.jdbc.driver; value=oracle.jdbc.OracleDriver
    [TopLink Finest]: 2008.01.09 07:36:00.781--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--property=toplink.jdbc.url; value=jdbc:oracle:thin:@//10.20.6.126:1521/region2
    [TopLink Info]: 2008.01.09 07:36:00.797--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))
    [TopLink Config]: 2008.01.09 07:36:00.812--ServerSession(1968077)--Connection(5182312)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
         platform=>OraclePlatform
         user name=> "rms"
         datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
    [TopLink Config]: 2008.01.09 07:36:01.797--ServerSession(1968077)--Connection(4252099)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
         User: RMS
         Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver  Version: 10.2.0.1.0
    [TopLink Config]: 2008.01.09 07:36:01.797--ServerSession(1968077)--Connection(5744890)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
         platform=>OraclePlatform
         user name=> "rms"
         datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
    [TopLink Config]: 2008.01.09 07:36:01.875--ServerSession(1968077)--Connection(5747801)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
         User: RMS
         Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver  Version: 10.2.0.1.0
    [TopLink Config]: 2008.01.09 07:36:01.891--ServerSession(1968077)--Connection(5760373)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
         platform=>OraclePlatform
         user name=> "rms"
         datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
    [TopLink Config]: 2008.01.09 07:36:01.969--ServerSession(1968077)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
         User: RMS
         Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver  Version: 10.2.0.1.0
    [TopLink Config]: 2008.01.09 07:36:01.969--ServerSession(1968077)--Connection(5497095)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
         platform=>OraclePlatform
         user name=> "rms"
         datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
    [TopLink Config]: 2008.01.09 07:36:02.047--ServerSession(1968077)--Connection(5500006)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
         User: RMS
         Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver  Version: 10.2.0.1.0
    [TopLink Config]: 2008.01.09 07:36:02.047--ServerSession(1968077)--Connection(5512041)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
         platform=>OraclePlatform
         user name=> "rms"
         datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
    [TopLink Config]: 2008.01.09 07:36:02.125--ServerSession(1968077)--Connection(5514977)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
         User: RMS
         Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver  Version: 10.2.0.1.0
    [TopLink Config]: 2008.01.09 07:36:02.125--ServerSession(1968077)--Connection(5527528)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
         platform=>OraclePlatform
         user name=> "rms"
         datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
    [TopLink Config]: 2008.01.09 07:36:02.203--ServerSession(1968077)--Connection(5530440)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
         User: RMS
         Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver  Version: 10.2.0.1.0
    [TopLink Config]: 2008.01.09 07:36:02.203--ServerSession(1968077)--Connection(5542993)--Thread(Thread[Main Thread,5,main])--connecting(DatabaseLogin(
         platform=>OraclePlatform
         user name=> "rms"
         datasource URL=> "jdbc:oracle:thin:@//10.20.6.126:1521/region2"
    [TopLink Config]: 2008.01.09 07:36:02.281--ServerSession(1968077)--Connection(5545904)--Thread(Thread[Main Thread,5,main])--Connected: jdbc:oracle:thin:@//10.20.6.126:1521/region2
         User: RMS
         Database: Oracle  Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver  Version: 10.2.0.1.0
    [TopLink Finest]: 2008.01.09 07:36:02.312--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--sequencing connected, state is Preallocation_NoTransaction_State
    [TopLink Info]: 2008.01.09 07:36:02.484--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--file:/D:/dev/bull/jpa_pk_bug/bin/-Test login successful
    [TopLink Finest]: 2008.01.09 07:36:02.484--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--end deploying Persistence Unit Test; state Deployed; factoryCount 1
    [TopLink Finer]: 2008.01.09 07:36:02.516--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--client acquired
    [TopLink Finest]: 2008.01.09 07:36:02.531--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query DoesExistQuery()
    [TopLink Finest]: 2008.01.09 07:36:02.547--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--PERSIST operation called on: test.jpa.entities.Person@563c8c.
    [TopLink Finest]: 2008.01.09 07:36:02.562--ClientSession(5666151)--Thread(Thread[Main Thread,5,main])--Execute query ValueReadQuery()
    [TopLink Fine]: 2008.01.09 07:36:02.594--ServerSession(1968077)--Connection(5747801)--Thread(Thread[Main Thread,5,main])--SELECT PERSONS_ID_SEQ.NEXTVAL FROM DUAL
    [TopLink Finest]: 2008.01.09 07:36:03.297--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--sequencing preallocation for PERSONS_ID_SEQ: objects: 1 , first: 5, last: 5
    [TopLink Finest]: 2008.01.09 07:36:03.312--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--assign sequence to the object (5 -> test.jpa.entities.Person@563c8c)
    [TopLink Finest]: 2008.01.09 07:36:03.328--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query ReadObjectQuery(test.jpa.entities.Person)
    [TopLink Fine]: 2008.01.09 07:36:03.438--ServerSession(1968077)--Connection(4252099)--Thread(Thread[Main Thread,5,main])--SELECT ID, NAME, MGR_ID FROM Persons WHERE (ID = ?)
         bind => [1]
    [TopLink Finest]: 2008.01.09 07:36:03.531--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Register the existing object test.jpa.entities.Person@3a4484
    [TopLink Finer]: 2008.01.09 07:36:03.625--ClientSession(5666151)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--begin transaction
    [TopLink Finest]: 2008.01.09 07:36:03.625--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query UpdateObjectQuery(test.jpa.entities.Person@3a57fa)
    [TopLink Finest]: 2008.01.09 07:36:03.641--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query WriteObjectQuery(test.jpa.entities.Person@563c8c)
    [TopLink Fine]: 2008.01.09 07:36:03.656--ClientSession(5666151)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--INSERT INTO Persons (ID, NAME, MGR_ID) VALUES (?, ?, ?)
         bind => [5, Boss, null]
    [TopLink Fine]: 2008.01.09 07:36:03.688--ClientSession(5666151)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--UPDATE Persons SET MGR_ID = ? WHERE (ID = ?)
         bind => [5, 1]
    [TopLink Finer]: 2008.01.09 07:36:03.703--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--begin unit of work commit
    [TopLink Finest]: 2008.01.09 07:36:03.703--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Execute query UpdateObjectQuery(test.jpa.entities.Person@563c8c)
    [TopLink Warning]: 2008.01.09 07:36:03.812--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--Local Exception Stack:
    Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: The attribute [id] of class [test.jpa.entities.Person] is mapped to a primary key column in the database. Updates are not allowed.
         at oracle.toplink.essentials.exceptions.ValidationException.primaryKeyUpdateDisallowed(ValidationException.java:2222)
         at oracle.toplink.essentials.mappings.foundation.AbstractDirectMapping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectMapping.java:750)
         at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.buildRowForUpdateWithChangeSet(ObjectBuilder.java:948)
         at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1263)
         at oracle.toplink.essentials.queryframework.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:91)
         at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:390)
         at oracle.toplink.essentials.queryframework.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:109)
         at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
         at oracle.toplink.essentials.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:555)
         at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:138)
         at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:110)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2233)
         at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
         at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:909)
         at oracle.toplink.essentials.internal.sessions.CommitManager.commitChangedObjectsForClassWithChangeSet(CommitManager.java:309)
         at oracle.toplink.essentials.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:195)
         at oracle.toplink.essentials.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:2657)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1044)
         at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:403)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1126)
         at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:107)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:856)
         at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:102)
         at oracle.toplink.essentials.internal.ejb.cmp3.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:60)
         at test.jpa.TestPkBug.runTest(TestPkBug.java:53)
         at test.jpa.TestPkBug.main(TestPkBug.java:95)
    [TopLink Finer]: 2008.01.09 07:36:03.828--ClientSession(5666151)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--rollback transaction
    [TopLink Finer]: 2008.01.09 07:36:03.844--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--release unit of work
    [TopLink Finer]: 2008.01.09 07:36:03.844--UnitOfWork(5663897)--Thread(Thread[Main Thread,5,main])--initialize identitymaps
    [TopLink Finer]: 2008.01.09 07:36:03.844--ClientSession(5666151)--Thread(Thread[Main Thread,5,main])--client released
    [TopLink Finest]: 2008.01.09 07:36:03.844--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--begin undeploying Persistence Unit Test; state Deployed; factoryCount 1
    [TopLink Finest]: 2008.01.09 07:36:03.844--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--sequencing disconnected
    [TopLink Config]: 2008.01.09 07:36:03.844--ServerSession(1968077)--Connection(4252099)--Thread(Thread[Main Thread,5,main])--disconnect
    [TopLink Finer]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--initialize identitymaps
    [TopLink Info]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--file:/D:/dev/bull/jpa_pk_bug/bin/-Test logout successful
    [TopLink Config]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Connection(5747801)--Thread(Thread[Main Thread,5,main])--disconnect
    [TopLink Config]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Connection(5182312)--Thread(Thread[Main Thread,5,main])--disconnect
    [TopLink Config]: 2008.01.09 07:36:03.859--ServerSession(1968077)--Connection(5500006)--Thread(Thread[Main Thread,5,main])--disconnect
    [TopLink Config]: 2008.01.09 07:36:03.875--ServerSession(1968077)--Connection(5514977)--Thread(Thread[Main Thread,5,main])--disconnect
    [TopLink Config]: 2008.01.09 07:36:03.875--ServerSession(1968077)--Connection(5530440)--Thread(Thread[Main Thread,5,main])--disconnect
    [TopLink Config]: 2008.01.09 07:36:03.875--ServerSession(1968077)--Connection(5545904)--Thread(Thread[Main Thread,5,main])--disconnect
    [TopLink Config]: 2008.01.09 07:36:03.891--ServerSession(1968077)--Connection(5763284)--Thread(Thread[Main Thread,5,main])--disconnect
    [TopLink Finest]: 2008.01.09 07:36:03.891--ServerSession(1968077)--Thread(Thread[Main Thread,5,main])--end undeploying Persistence Unit Test; state Undeployed; factoryCount 0
    Exception in thread "Main Thread" javax.persistence.RollbackException: Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: The attribute [id] of class [test.jpa.entities.Person] is mapped to a primary key column in the database. Updates are not allowed.
         at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:120)
         at oracle.toplink.essentials.internal.ejb.cmp3.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:60)
         at test.jpa.TestPkBug.runTest(TestPkBug.java:53)
         at test.jpa.TestPkBug.main(TestPkBug.java:95)
    Caused by: Exception [TOPLINK-7251] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: The attribute [id] of class [test.jpa.entities.Person] is mapped to a primary key column in the database. Updates are not allowed.
         at oracle.toplink.essentials.exceptions.ValidationException.primaryKeyUpdateDisallowed(ValidationException.java:2222)
         at oracle.toplink.essentials.mappings.foundation.AbstractDirectMapping.writeFromObjectIntoRowWithChangeRecord(AbstractDirectMapping.java:750)
         at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.buildRowForUpdateWithChangeSet(ObjectBuilder.java:948)
         at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1263)
         at oracle.toplink.essentials.queryframework.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:91)
         at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:390)
         at oracle.toplink.essentials.queryframework.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:109)
         at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
         at oracle.toplink.essentials.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:555)
         at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:138)
         at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:110)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2233)
         at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
         at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:909)
         at oracle.toplink.essentials.internal.sessions.CommitManager.commitChangedObjectsForClassWithChangeSet(CommitManager.java:309)
         at oracle.toplink.essentials.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:195)
         at oracle.toplink.essentials.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:2657)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1044)
         at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:403)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1126)
         at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:107)
         at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:856)
         at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:102)
         ... 3 moreEDIT: Are you using the EXACT Test Case as I have described it in the previous posts? It's important that you commit(), and not rollback(), the transaction after the flush.
    EDIT: Updated the log because I found out that I had made a small change to the original Test Case while I was trying to find a workaround. The current log is produced by the EXACT Test Case I described in my previous posts.
    Message was edited by:
    bisser

  • How can I modify a column to a primary key column

    Hi,
    I've created a table with no primary key. How I can set the primary key column now? The datatype of the "primary key" column is Raw(35).
    Thanks,
    Mike

    Mike,
    Issue the following command:
    ALTER TABLE table_name
    ADD CONSTRAINT constraint_name PRIMARY KEY(column_name);
    NOTE: If you want to place the primary key data in a separate tablespace, then you can add the key word USING INDEX TABLESPACE after the column_name.
    Regards,
    John

  • Updation of table records having 5-6 primary key columns.

    I have a table structure having 12 primary composite keys.I have created report + form on this table.My requirement is to update the table by using form items fields.I am taking help of url option on report attribute page of application to fetch data on form page when we click on edit link of report page.Now i am having two problems which are as follows:-
    (i)I am unable to update data as requirement is to update 5 to 6 primary fields along with other non primary keys.I tried to create Pl/SQL process which will run update query but this process is not updating values.Is there any way that i could fetch data direct from database table in query rather then taking item values.Is there any other workaround?
    (ii)One of the primary key column contains records which have ' , ' in them .For ex:- cluth,bearing.So when i get navigated to edit page i am only getting text displayed as clutch i.e. text before ',' is getting displayed in text field while comma and the text after this is not getting displayed in text field of form page.
    Any solutions will be very helpful.
    Thanks
    Abhi

    Hello Abhi,
    >> I am unable to update data as requirement is to update 5 to 6 primary fields along with other non primary keys
    APEX wizards support a composite PK with up to 2 segments only. For every other scenario, you’ll have to manually create your DML code.
    If you have control over your data model, I would listen very carefully to Andre advices. Using a single segment PK is the best practice way. If you can’t add PK to your table, it seems that you’ll have to write your own DML code. The Object Browser option of creating a Package with methods on database table(s) can be a great help.
    >> … I am taking help of url option … One of the primary key column contains records which have ' , ' in them …
    Using the f?p notation, to pass a comma in an item value, you should enclose the characters with backslashes. For example,
    \cluth,bearing\In your case, it should be the item/column notation.
    http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/concept.htm#BCEDJBEH
    Regards,
    Arie.
    ♦ Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    ♦ Author of Oracle Application Express 3.2 – The Essentials and More

  • How to change (decrease) primary key column length?

    Hi all,
    I have plenty of data in the table and I need to decrease the primary key column from CHAR(17) to CHAR(13).
    I try to use:
    ALTER TABLE xx MODIFY (prmy_key (13));
    but Oracle give:
    ERROR at line 1:
    ORA-01441: column to be modified must be empty to decrease column length
    Can anyone give me advice on what is the best way to decrease column length? Thanks in advance for your help.

    To add to the above, I have done a simple test in the lines that I was suggesting the solution for this problem,
       CREATE TABLE testA
       (pk_col   varchar2(20), jd date, constraint pk1 PRIMARY KEY(pk_col));
       --Insert data into testA
       create table testB as select * from testA;
       TRUNCATE table testA;
       ALTER TABLE testA modify(pk_col VARCHAR2(10));   
       INSERT INTO testA SELECT substr(pk_col, 1, 10), jd from testB;
       DROP TABLE testB;
       Select constraint_name, constraint_type, status from all_constraints
       Where table_name = 'TESTA';
       CONSTRAINT_NAME                C STATUS
       PK1                            P ENABLEDAlter command is successful as the table is empty. TRUNCATE flushes the data and resets the high water mark keeping all the constraints. If we safely want to use the TRUNCATE as far as storage issues are concerned,
    TRUNCATE table table_name reuse storage;
    I think, this would accoplish what has been asked.
    Let me know,
    SriDHAR

  • 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

  • No Primary Key Column set. error

    Hi all,
    Firstly, thank you to DWFAQ for advice a tutorials.
    Secondly, I have built a contact form using the update record
    form wizard in ADDT -
    http://dwfaq.info/home.php?id=4
    I have hit a problem, when running the form I get the
    following error:
    Error:
    Internal error.
    Developer Details:
    tNG_update.prepareSQL:
    No Primary Key Column was set. (UPD_NO_PK_SET)
    tNG Execution Trace - VIEW
    * tNG_update.executeTransaction
    o STARTER.Trigger_Default_Starter
    o tNG_update.doTransaction
    + BEFORE.Trigger_Default_saveData
    # tNG_update.saveData
    + BEFORE.Trigger_Default_FormValidation
    + tNG_update.prepareSQL*
    o tNG_update.getRecordset
    o tNG_update.getFakeRsArr
    o tNG_update.getLocalRecordset
    o tNG_update.getFakeRecordset
    Could somebody please help - I'm so close it hurts ;-)
    Thank you
    NJ

    Heya,
    Looks like your DB is all setup correctly it must be the
    primary key in the transaction of the script.
    Make sure id is set as the primary key in your Update Record
    Form Wizard. You php code should look something like this:
    // Add columns
    $upd_contact->setTable("cvform");
    $upd_contact->addColumn("firstname", "STRING_TYPE",
    "POST", "firstname");
    $upd_contact->addColumn("lastname", "STRING_TYPE", "POST",
    "lastname");
    $upd_contact->addColumn("email", "STRING_TYPE", "POST",
    "email");
    $upd_contact->addColumn("message", "STRING_TYPE", "POST",
    "message");
    $upd_contact->addColumn("attachment", "FILE_TYPE",
    "FILES", "attachment");
    $upd_contact->addColumn("phonenumber", "STRING_TYPE",
    "POST", "phonenumber");
    $upd_contact->setPrimaryKey("id", "NUMERIC_TYPE", "VALUE",
    "id");
    // Execute all the registered transactions
    $tNGs->executeTransactions();
    You may have to post your script to see what the problem is.
    Most likely something not followed correctly in the tutorial. If
    you are able to post your php script as a text file then link to
    the file here with .txt extension I can take a look at it and see
    where the problem is. Make sure to remove any info that may
    compromise your database when providing your php script or contact
    me through my website and I can help you out off the forum.
    Hope that helps!

  • FillSchema picks too many primary key columns

    I don't know whether this is an ODP.NET error or a Microsoft error.
    Oracle9i Release 9.2.0.1.0
    ODP.NET 9.2.0.4
    .NET Framework 1.1
    Create a table with one primary key column and one unique column and name the primary key column like the unique column with the suffix "_ID":
    CREATE TABLE t_bib_uebertrag_kap(
    &nbsp kapazitaet_id NUMBER(8) NOT NULL
    &nbsp&nbsp CONSTRAINT pk_kapa primary key,
    &nbsp kapazitaet VARCHAR2(15) NOT NULL
    &nbsp&nbsp CONSTRAINT a_un_kapa unique,
    &nbsp geschwindigkeit NUMBER(12) NOT NULL,
    &nbsp bemerkung VARCHAR2(255)
    After calling FillSchema on this table the PrimaryKey property of the DataTable contains 2 columns: KAPAZITAET_ID and KAPAZITAET.
    The same happens with other tables and similar column names
    R. Lüthke

    Tony, I'm gonna find time to try this because I was thinking it probably would be a double check.
    BUT... Oracle is written in C, and I imagine the extra check as a simple if comparison for the new value versus a constant NULL value. Kind of like checking for end of string. It's already doing things like checking datatypes and that as it inserts data, and I don't think this additional check (if it even exists) would add any significant overhead.
    But unless I find a much larger performance hit than I expect, I'm gonna stick with creating the NOT NULL's explicitly. Good data modelling trumps small performance tricks for me.
    My main worry is if/when somebody removes the primary key constraint (such as the example above where they might do a CREATE TABLE x AS SELECT * FROM y). Or if the data model gets updated to where the primary key becomes just a unique key, then the NOT NULL goes away when it shouldn't. I don't like basic table and column properties changing.
    Okay.. test done. Ran about 31,000 records from dba_tables through an insert into two tables, both with primary keys and one with explicit NOT NULLs. No measurable difference in stats detected.
    With NOT NULL and PRIMARY KEY:
    call count cpu elapsed disk query current rows
    Parse 1 0.35 0.35 0 0 0 0
    Execute 1 1.88 1.83 0 24792 35887 30954
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 2.24 2.18 0 24792 35887 30954
    Now with only PRIMARY KEY.
    call count cpu elapsed disk query current rows
    Parse 1 0.37 0.36 0 0 0 0
    Execute 1 1.87 1.83 0 24792 35887 30954
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 2.24 2.19 0 24792 35887 30954

  • How to find primary key?

    I am trying to impliment a load using JDBC wherein I read the table name, some column names, and associated
    column data from a file (delimited or XML). The primary key columns are in the column names / data BUT I don't
    know which columns they are (based on the file I'm reading). Even if this information was in the file, I would need to
    verify the table I'm targeting does in fact have that primary key. I can insert the records fine BUT to use the records
    to update I need to determine from the database which are the primary key columns (by name).
    Essentially I'm trying to do the following:
    insert record into table
    if fails because of duplicate primary key
    determine the primary key of the current table
    retrieve the already existing record
    modify the retrieved record using my load data
    update the already existing record in the database
    My primary concern, now, is Oracle although I'm hoping to impliment this in as portable a fashion as possible.
    Thanks.
    R.Parr
    TemporalArts
    608.833.4578
    null

    You can check the DBA_CONSTRAINTS view for that: http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_1037.htm#i1576022

  • ORA-14402: updating partition key column would cause a partition change

    Hi,
    When I am trying to execute an update statement where i am tring to update date values emp_det from 11-oct-2010 to 12-nov-2010.
    Oracle throws an error :
    ORA-14402
    updating partition key column would cause a partition change
    I think that this is because emp_det is a partitioning key of a partitioned table.
    Oracle documentation says that
    "UPDATE will fail if you change a value in the column that would move the
    row to a different partition or subpartition, unless you enable row
    movement" .
    alter table t enable row movement;
    I did not understand what is meant by "enable row movement".
    I cannot drop the partitions and recreate it after updating the table and also i don't have proper priviliges for enale row movement syntax
    because of the lack of privileges. How to solve this is issues with out row movement and recreate partition.
    Can this be done by a developer or is there any other way to execute update in this case? its urgent.. pls help..
    thanks in advance..
    By
    Sivaraman
    Edited by: kn_sivaraman on Nov 1, 2010 2:32 AM

    kn_sivaraman wrote:
    I did not understand what is meant by "enable row movement". Each partition in partitioned table is physically separate segment. Assume you have a row that belongs to partition A stored in segment A and you change row's partitioning column to value that belongs to partition B - you have an issue since updated row can't be now stored in segment A anymore. By default such update is not allowed and you get an error. You can enable row movement and Oracle will move row to target partition:
    SQL> CREATE TABLE SALES_LIST(
      2                          SALESMAN_ID NUMBER(5,0),
      3                          SALESMAN_NAME VARCHAR2(30),
      4                          SALES_STATE VARCHAR2(20),
      5                          SALES_AMOUNT NUMBER(10,0),
      6                          SALES_DATE DATE
      7                         )
      8    PARTITION BY LIST(SALES_STATE)
      9    (
    10     PARTITION SALES_WEST     VALUES('California', 'Hawaii'),
    11     PARTITION SALES_EAST     VALUES('New York', 'Virginia', 'Florida'),
    12     PARTITION SALES_CENTRAL  VALUES('Texas', 'Illinois'),
    13     PARTITION SALES_OTHER    VALUES(DEFAULT)
    14    )
    15  /
    Table created.
    SQL> insert
      2    into sales_list
      3    values(
      4           1,
      5           'Sam',
      6           'Texas',
      7           1000,
      8           sysdate
      9          )
    10  /
    1 row created.
    SQL> update sales_list
      2    set  sales_state = 'New York'
      3    where sales_state = 'Texas'
      4  /
    update sales_list
    ERROR at line 1:
    ORA-14402: updating partition key column would cause a partition change
    SQL> alter table sales_list enable row movement
      2  /
    Table altered.
    SQL> update sales_list
      2    set  sales_state = 'New York'
      3    where sales_state = 'Texas'
      4  /
    1 row updated.
    SQL> SY.

  • Partition key on non primary key column

    I have scenario where the table has defined non primary key column as "partition key".
    I was wondering how it will affect the purge/archive process if the index and table are using different column (they are not aligned)?
    What should be the solution to this scenario?
    Can I use the non primary key column as partition key? Is this affect purging/archiving or switching -IN or OUT partitions?
    Here is the article which Im following but didn't get the precise answer:
    "When the indexes and the table use the same partitioning function and columns in the same order, the table and index
    are aligned." 
    https://msdn.microsoft.com/en-US/library/ms345146%28v=SQL.90%29.aspx?f=255&MSPPError=-2147217396#sql2k5parti_topic9
    Look at "Index
    Partitioning" and "Defining
    the Partitioning Key" section.
    ZK

    If it non aligned, you cannot do switching in or out.  to switch, you should have aligned partitons.
    Hope it Helps!!

  • How to create Primary key

    I want to insert HOSTID that has unique values in a new application in a primary key column in database.
    I am starting with h000000001
    and I want to go from that to h000000002
    and .... h0000000010 , 11, 12 etc etc.
    How do I do this?
    I did this:
    rs = stmt.executeQuery("select wlbmach_host_id from wlbmach order by wlbmach_host_id desc");
    // I am getting the greatest value eg: h000999999
    if (rs.next())
    getHostID = (String)rs.getString("wlbmach_host_id");
    //Get the h0009999999
    getStringNumber = getHostID.substring(1,10);
    //This gives me 9999999
    try
    {getNum = Integer.parseInt(getStringNumber);
    //change number to integer so I can add 1 to it
    getNum=getNum+1;
    getStringNumber=Integer.toString(getNum);//make that a string
    getHostID="h"+getNum;//add h to it
    }//try
    catch(Exception e)
    {System.out.println("NumberFormatException might have occured");%>
    else
         System.out.println("Assigning first HostID");
         getHostID = "h00000001";
    System.out.println("HostID is "+getHostID);
    But gives Exception:String index out of range: 10.. My column can take 10 varchar ??
    Can someone help .. Is this the right way to do it ?
    Is there a better way to generate primay keys?

    Why are you making life difficult??? Why not use the SEQUENCE object (if you are using Oracle)? You can retrieve next value by "Select sequencename.nextval from dual" as the query...you will get your number. Also, when two requests are made at the same time, Oracle takes care of this problem for you...you do not need to synchronize the method in JAVA. Do some research in this...I think you will like it.

Maybe you are looking for

  • "Contains no actionscript" - yes it does!

    Hi, I'm new to Flash and actionscripting, but this issue also seems to boggle the minds of more experienced Flash users in the company I work for, and nobody has come up with an answer to this. I use Flash CS3 on PC. I should add that I also use the

  • Midi not reading A SAMSON 61 CARBON MIDI CONTROLLER HEEN HELP

    NEED HELP MIDI WILL READ 61 SAMSON MIDI KEYBOARD BUT IT WILL READ THE 49 KEY VERSION

  • Running OpenSSL command through Java Program

    How do I execute openssl commands through a java program? Any packages or wrapper classes are there? Please help. Thanks.

  • Account restricted

    Hello again, This is my third request for help.  My account is restricted for reasons unknown.  I have changed my password as per the many other messages on this inexplicible topic.  Please help. Thank you!

  • RAW Files: unable to open Sony SLT A58 Raw files in PSE10

    I have a Sony SLT 58 camera and have found that Elements 10 will not open RAW files from this camera.  However, an Earlier a350 that I owned had no problems.  Has any one have any thoughts as to why this is?