Primary Key in INSERTs

Hi!! :-)
Im currently trying to access some Postgres-database from an Enterprise-App running inside Sun App Server 9... Some of th tables have a primary-key-field with type SERIAL, so Postgres creates the value for those fields!!
Now: How can i achieve, that the app-server does not try to write into those fields??
Specifying insertable=false is ignored and when i specify insertable=false and updatable=false i get the following error on deployment:
Deploying application in domain failed; Exception [TOPLINK-0] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.IntegrityException Descriptor Exceptions: --------------------------------------------------------- Exception [TOPLINK-46] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DescriptorException Exception Description: There should be one non-read-only mapping defined for the primary key field [dsl_payments.id]. Descriptor: RelationalDescriptor(de.meitnerweg.netzag.dsl.persistence.DslPayment --> [DatabaseTable(dsl_payments)]) Runtime Exceptions: --------------------------------------------------------- Exception [TOPLINK-0] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.IntegrityException Descriptor Exceptions: --------------------------------------------------------- Exception [TOPLINK-46] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DescriptorException Exception Description: There should be one non-read-only mapping defined for the primary key field [dsl_payments.id]. Descriptor: RelationalDescriptor(de.meitnerweg.netzag.dsl.persistence.DslPayment --> [DatabaseTable(dsl_payments)]) Runtime Exceptions: ---------------------------------------------------------
Anyone ideas??
:-)

The blog here describes how to work with this situation.
http://blogs.sun.com/Glassfish_PostgreSQL/entry/introducing_support_for_postgresql_in
Look into known Issues / Workaround sections.

Similar Messages

  • Help me to return the primary key after insert the row

    Hi
    I am using JDBC, with oracle database. i have welformed normalization tables .i am inserting parent table with dynamic sequence number as primary key .after inserting i need inserted row primary key .how to get the inserted row primary key with out using select statement
    please help me
    Thanks in advance
    Edited by: 849614 on Apr 4, 2011 5:41 AM
    Edited by: 849614 on Apr 4, 2011 5:54 AM

    Hello
    If I undestand you, I think you should do this:
    Connection conexion = dataSource.getConnection();
    int idCenter=-1;
    String query = "Begin Insert into CENTER (NAME_CENTER) values (?) returning ID_CENTER into ?; end";
    callableStatement = conexion.prepareCall(query.toString());     
         callableStatement.setString(1, "Center name");               
         callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
              callableStatement.executeUpdate();
              idCenter=callableStatement.getInt(2);
    This way, you have in idCenter the primary key of the line that has just been inserted.
    Edited by: cris on 05-abr-2011 5:28

  • How do I autogen a value for primary key on inserts

    I'm running 4.0. I am writing an app that maintains distributed database inventory information. All of my tables have surrogate numeric primary keys. I have created several report/form combinations. From the report, I can choose to create a new instance of an object; Server for instance. When I click the "Add Server >" button, the Detail page opens for me to create the new entry. On this page, I need to have the Server_ID autogenerated. I'm thinking something as simple as "Select (max(server_id)+1) from Server" should do. In fact, it looks like it is going to work because the field gets populated correctly. But, when I click the "Create" button on this page I get an error that says the Server_ID is null. Seems like the generated value isn't making it to the INSERT statement.
    On the Page Definition, I have Server_ID set as Display Only and in the Source section for the attribute I have "Only when current value in session state is null" selected and "SQL Query (return single value)" selected with "Select (max(server_id)+1) from Server" in the "Source value or expresssion" field.

    Hi Ken,
    From your description it appears you want the new server ID to be assigned and show on the page prior to collecting the rest of the information, rather than assigning it upon saving the new row. What you're doing will get the next available ID, but what happens if two or more people are entering new servers at once? There's a good chance they'll all get the same next ID.
    Tony's suggestion will ensure the uniqueness of the server ID because it'll get assigned upon saving the row, rather than on display of the page where a user could leave the screen sitting there while others "take" that next ID. You can return the value that the trigger assigns for display - if you're using an Automatic Row Processing process, see the Return Key into Item setting.
    If you're going to stick with your approach and just need to know how to make sure that field is included in the INSERT, you need to create a computation on that item and move your "select max..." there, and then for the server ID item change the Source Used to "Always...", Source Type to Database Column, and specify the column name from the table in the Source Value. The reason is hasn't been working is that field isn't currently mapped to the table column.
    Hope this helps,
    John

  • Returning autogenerated primary key after insertion

    Hi
    I am inserting a row into the database using simple jdbc statement. The primary key for that row is autogenerated by the database.
    Is there any way to get the primary key and return it to the user?

    PreparedStatement ps = con.preparedStatement("INSERT INTO Table (title, name) VALUES ("test", "name")", PreparedStatement.RETURN_GENERATED_KEYS);
    ps.executrUpdate();
    ResultSet rs = ps.getGeneratedKeys();
    while (rs.next()) {
    primaryKey = rs.getInt(1);
    }

  • How to get the inserted row primary key with out  using select statement

    how to return the primary key of inserted row ,with out using select statement
    Edited by: 849614 on Apr 4, 2011 6:13 AM

    yes thanks to all ,who helped me .its working fine
    getGeneratedKeys
    String hh = "INSERT INTO DIPOFFERTE (DIPOFFERTEID,AUDITUSERIDMODIFIED)VALUES(DIPOFFERTE_SEQ.nextval,?)";
              String generatedColumns[] = {"DIPOFFERTEID"};
              PreparedStatement preparedStatement = null;
              try {
                   //String gen[] = {"DIPOFFERTEID"};
                   PreparedStatement pstmt = conn.prepareStatement(hh, generatedColumns);
                   pstmt.setLong(1, 1);
                   pstmt.executeUpdate();
                   ResultSet rs = pstmt.getGeneratedKeys();
                   rs.next();
    //               The generated order id
                   long orderId = rs.getLong(1);

  • Null value in detail table's primary key

    I use Business Components Data Form to define a master-detail java panel.
    I don't display the primary key column in the detail grid control.
    Then I click on "+" to add a row, enter a value (the 2nd part of the detail table's primary key) and click commit.
    I get an error saying that the primary key column that's not displayed is null and the row cann't be committed.
    How do I fix this error?

    My fields are varchar2's.
    -- simplified to protect the guilty:
    -- (made up from memory, so sql keywords may --be misspelled, but you get the idea)
    create table proj (
    proj varchar2(10) not null,
    constraint proj_pk
    primary key(proj)
    insert into proj values ('abc');
    commit;
    -- this table has legal values for -- the master.legal field.
    -- in master, legal was changed to a -- ComboBoxControl control from -- TextFieldControl that the wizard -- generated.
    create table legal_values (
    proj varchar2(10) not null,
    legal varchar2(10) not null,
    display_order integer not null,
    constraint legal_values_pk
    primary key (proj, legal)
    insert into legal_values
    values ('abc', 'one', 1);
    insert into legal_values
    values ('abc', 'two', 2);
    insert into legal_values
    values ('abc', 'three', 3);
    commit;
    create table master (
    proj varchar2(10) not null,
    masterKey varchar2(15) not null,
    legal varchar2(10) not null,
    constraint master_pk
    primary key (proj, masterKey)
    create table detail (
    proj varchar(10) not null,
    masterKey varchar(15) not null,
    detailkey varchar(10) not null,
    display_order integer not null,
    status varchar2(12) not null, -- user can only update this field
    constraint detail_pk
    primary key(proj, masterkey, detailkey)
    -- legal rows for detail table
    create table detail_values (
    proj varchar2(10) not null,
    detailkey varchar2(10) not null,
    display_order integer not null,
    constraint detail_values_pk
    primary key(proj, detailkey)
    insert into detail_values values
    ('abc', 'status a', 1);
    insert into detail_values values
    ('abc', 'status b', 2);
    commit;
    -- if their is a foriegn key on details back
    -- to master, then you get the
    -- "mutating table" error when trigger
    -- occurs.
    create or replace trigger master_tr
    after insert on master
    for each row
    begin
    insert into detail
    (masterKey, detailKey, status, display_order, status)
    select :new.masterkey, detail_key, display_order, ' '
    from detail_values;
    end;
    -- detail.status is a comboboxControl getting --its values of of another db table too.
    -- there's also "after update" triggers on master and detail tables that copy the record to master_history and "detail_history" tables if the corresponding table is modified. Thus we have a history of the changes made to the records. The 2 history tables have 2 additional fields than their parents, "modified_date date default sysdate not null" and "modified_by varchar2(30) default user not null" that record when and who made the change. There's also a change type field that records where the change is an insert, delete or update (there 3 triggers per table , so we can correctly record change type as being insert, delete or update into the change_type field).
    If you want to make it more real to life, the status value is initially blank, then can be changed to a legal status value (complete or not complete), but can not be changed back to blank.
    ***P.S. I have to have this ready for production by monday.****
    P.P.S After you reply and change to ComboBoxControls in 2 places, try changing the table names and/or the column names (say to follow the DBA's naming convention) or add another field to the composite primary key (and unstated foriegn key) (using drop table/create table). Now try getting the existing code to run. No writing down the old/new table (or column) name pair names. Just run the code and try to fix the code based on the error messages. Are the error messages giving you adequate information to find the problem?

  • ADF and Primary Key

    Hi!
    I'm using PostgreSQL as the DB and set for PK an attribute named ID that's of type serial. It's auto-incremented when the row is go to be inserted.
    I've read in other posts like this one -> Primary key during Insert
    to set type to DBSequence, but later the compiler gives me an error saying DBSequence doesn't exist.
    How can I get this working? Or how can I put a value in ID in the application's code that's de MAX(ID) +1?
    Thanks

    Your first image - setting the type of the id as a DBSequence is correct. What you are saying by doing this is that the database is automatically setting the value of your primary key. This means that when the Entity object does DML, it doesn't require the user to supply the value, it doesn't set it itself, and it retrieves the value as soon as the insert is complete. In Oracle, it would use a "RETURNING" clause - I don't know if Postgres SQL does this.
    Given that DBSequence is saying that the DATABASE is setting the value, I'm not sure what you are trying to do in your second image. You seem to have a Java object that has a getter and setter for the column. I'm not sure what the purpose of this object is, especially if Postgres SQL is setting the id, not the application.
    When you create an Entity Object in ADF Business components, it can optionally write the Java classes that implement the object, so that you can override certain functionality. Choose the "Java" menu option on the Entity Object definition screen and check the appropriate checkboxes to get it to write Java that you can change. If your Entity is named MyEntity, JDeveloper will generate MyEntityImpl,java. If you edit this file, you will see that it already has a getter and a setter for your id. I think that the datatype that it will assign is "Number", not "DBSequence". If you really need to change the getter and setter, do it here.

  • SQLLDR direct path allows duplicates in primary key

    I would like to use sqlldr direct path to load millions of records in the table but direct path allows duplicates on the primary key constraints.
    inserts duplicates
    sqlldr deploy_ctl/deploy_ctl@dba01mdm control=ctl_test.ctl direct=true
    primary key is enabled
    I am not understanding the behavior that why primary key is still enabled -- (logically it should have disabled than inserted duplicates)
    does not insert duplicates
    sqlldr deploy_ctl/deploy_ctl@dba01mdm control=ctl_test.ctl
    primary key is enabled
    Please can I know if there is any work around to use direct path with primary constraints in place.

    Dear,
    Look at the following example
    mhouri.world> drop table t1;
    Table dropped.
    mhouri.world> create table t1 (id number);
    Table created.
    mhouri.world> alter table t1 add constraint t1_pk primary key (id);
    Table altered.
    mhouri.world> select table_name, index_name, status
      2  from user_indexes
      3  where table_name = 'T1';
    TABLE_NAME                     INDEX_NAME                     STATUS           
    T1                             T1_PK                          VALID            
    mhouri.world> select count(1) from t1;
      COUNT(1)                                                                     
             0                                                                      and here call sqlldr
    C:\>sqlldr xxx/xxx@xxxx control=c.ctl bad=c.bad direct=trueAnd see what happen to the primary key index
    mhouri.world> select count(1) from t1;
      COUNT(1)                                                                     
             4                                                                     
    mhouri.world> select * from t1;
            ID                                                                     
             1                                                                     
             2                                                                     
             2                                                                     
             3                                                                     
    mhouri.world> select table_name, index_name, status
      2  from user_indexes
      3  where table_name = 'T1';
    TABLE_NAME                     INDEX_NAME                     STATUS           
    T1                             T1_PK                          UNUSABLE         
    mhouri.world> alter index t1_pk rebuild;
    alter index t1_pk rebuild
    ERROR at line 1:
    ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found The primary key index is made unusable and this is why you have duplicate records
    best regards
    Mohamed Houri

  • Primary key  & foriegn key

    can i create more than one primary key in database table..?what is the function of primary key compare to foriegn key

    Hi
    Primary Key:
    it is useful to uniquely identify the rows in a table by one or more columns so that you can process them in a specified sequence, for example. You can do this by assigning a “primary key.” The column names that are to create the table key are represented by the keywords PRIMARY KEY. The input values of the key columns defined in this way must not be a NULL value.
    You can use the primary key to insert rows in a table in the same way as you insert rows in a base table when no primary key is defined. However, the system outputs an error message if you attempt to insert an existing value into the primary key column a second time, since the uniqueness of the column is ensured by defining the primary key.
    A primary key can consist of multiple columns. However, it is unusual for a key to be constructed from more than five columns, since this makes it difficult for users to enter unique values. The arrangement of the columns behind the keywords PRIMARY KEY defines the key sequence.
    Foreign Keys :
    You can define the relationships between tables in the ABAP Dictionary by creating foreign keys.
    Using foreign keys, you can easily create value checks for input fields. Foreign keys can also be used to link several tables in a  view or a  lock object.
    Reward Points if useful

  • 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

  • Parameters in Url..how do I use login information to insert the primary key

    Uggg, it is 3 am, I am so tired. Please help.
    I have made a registration page for my site. Hurray it works.
    Login Page. It works
    Protected some pages. Works
    Now I am trying to make a page that the users can go to and update their user information. User name, password, email ect.
    I can get it to prepopulate if I put ?id=3, or someother primary key in the url by hand.....and it does update the data.... but I can't, for the life of me, figure out how to make it use the users login information to get and insert the primary key in the url from the link to the update page.
    I have used the hyperlink box and chose the updateaccount.php file, then went to parameters and selected Name: id Value: I chose id from the dropdown from the data base. This puts in an echo that looks like it should work. NO SUCH LUCK.
    Pleeeese!!! What am I doing wrong.
    I am a total novice. Done a few static sites. So please speak slowly.
    Thanks sooooo much

    I really can´t recommend exposing critical stuff like e.g. the user´s login_id in the URL, because once it´s visible, it can be changed by anyone. Better insert the Session Variable kt_login_id, which will only be availabe on a custom PHP page when inserting...
    <?php session_start(); ?>
    ...on line 1 of this document.
    Cheers,
    Günter

  • Primary Key rule Violation error while Insert Record in Compact DB

    Hi All,
    I have One Table in Server Name "Student"  when i Synchronize this with the help of Microsoft Synchronization Framework
    same Table schema with Data has been create in CompactDataBase.
    When i insert data in CompactDataDase it give me Primary Key Violation error.
    Please Suggest
    Example
    Table Structure is as Follows:-
    Create Table Student(
    [Emp_id] int IDENTITY(1,1) NotNull,[Emp_Name] int NOTNULL );insert into Student Values('John');insert into Student Values('Joe');Thanks & RegardsNamit Jain

    try this and see if it solves,
    also, Emp_name data type is int. it should be varchar.
    I suspect the reason is because you already have some data in student table but you identity seeds were not updated and hence it is trying to insert a row with emp_id value that already exists.and hence the primary key violation. also, your table DDL did
    not really have an primary key but it would still error since you are inserting duplicate row in the identity column.
    so, try resetting the identity seed value to the max(emp_id) in the table.
    select max(Emp_ID) from  student
    --use the output of the above statement
    DBCC CHECKIDENT ('Student', RESEED,<<--use the output of the above statement-->>)
    --your max(emp_id) should match with last_value column in the below( do not if this query would run in compact DB though)
    select seed_value,increment_value,last_value from sys.identity_columns where object_id=object_id('Student')
    now, try your insert.
    Hope it Helps!!

  • Task-flow for inserting a record in a popup: error on primary key.

    Hi all,
    I am using Jdeveloper 11.1.1.2.
    I am trying to display a bounded task flow in a popup launched from a page. I am following the steps in: http://www.oracle.com/technology/products/jdev/tips/fnimphius/popupinuishell/declarative_popup_in_uishell.html
    I have a view object (myVO) and I have a page (page1), where I can edit the records of myVO. In this page I have a button that launches (in a window) a task-flow (insertTF, that uses existing transaction if possible, composed by page2 and page3) where I can insert a new record in two step (using a train).
    At the end of the train I can save or cancel (task flow return activity) the inserting record.
    The button cancel work well, but the button save does not. When I click on it, I return in page1 but I have this error: Error: another user modified row with primary key oracle.jbo.Key [[+numberOfKey+]].
    If I see the database navigator or I refresh the page, I can see the record just inserted.
    How can I do to remove this error?
    Thank you
    Andrea
    Edited by: Andrea9 on 10-dic-2009 06:39

    There are default values coming from the DB. There are also default values that I have setted in myModel on myEO.
    I am the only user manages the database, there are no other users.
    So, how can I solve this problem? Have I to remove the default value on inserting? From DB or from myEO?
    thanks in advance
    Andrea

  • Insert values of form on a table with compound primary keys in APEX

    Good evening,
    I have a table with compoud primay keys. On ER model I had a many to many relation and when I coverted to relational model I've got a table with the primary keys of the two entities.
    My problem now is that I am trying to build an APEX application with a Form/Report and I want to insert a tuple both on the "entity" and on the table with two primary keys.
    I created a trigger with
    CREATE OR REPLACE TRIGGER ins_key_elem
    INSTEAD OF INSERT
    ON v_key_elem
    REFERENCING NEW AS NEW
    FOR EACH ROW
    BEGIN
    INSERT INTO elem_type (elem_key, type_key)
    VALUES (:NEW.elem_key, :NEW.type_key);
    INSERT INTO elem(elem_key, name)
    VALUES (:NEW.elem_key, :NEW.name);
    END;
    Is that ok? If it is, now how I can use that trigger to do what I need? i.e. insert the tuple on the two tables when I use the create button of the form
    Edited by: 934530 on May 15, 2012 2:36 PM

    Nevermind...figured it out. Was able to set the value on the Report Attributes page.

  • Issue with INSERT INTO, throws primary key violation error even if the target table is empty

    Hi,
    I am running a simple
    INSERT INTO Table 1 (column 1, column 2, ....., column n)
    SELECT column 1, column 2, ....., column n FROM Table 2
    Table 1 and Table 2 have same definition(schema).
    Table 1 is empty and Table 2 has all the data. Column 1 is primary key and there is NO identity column.
    This statement still throws Primary key violation error. Am clueless about this? 
    How can this happen when the target table is totally empty? 
    Chintu

    Nope thats not true
    Either you're not inserting to the right table or in the background some other trigger code is getting fired which is inserting into some table which causes a PK violation. 
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for