Problem: insert id, when table is updated

Hello,
I have a Problem:
I have an external table which is permanently updatet and I access this table by a database link.
My problem is, that this table hasn't got an ID column,but I need one to build an interesting Application. So my idea is, to create a view in which you can see the main table through the database link and an column with an ID....
But this ID must be updatet permanently when a new row is insertet into the main table!
I hope you understand what I mean....
And I hope you can help me!
Thanks,
Tim

You can use Sequence for this.
SQL> CREATE SEQUENCE SEQ_1 INCREMENT BY 1
  2  /
Sequence created.And use a trigger before insert.
CREATE OR REPLACE TRIGGER TRG_TAB1_BRI
BEFORE INSERT
ON TABLE_1 -- Your table
FOR EACH ROW
BEGIN
    SELECT SEQ_1.NEXTVAL
    INTO :NEW.ID  -- Your ID Column
    FROM DUAL;
END;Sarma.

Similar Messages

  • Trigger with Condition problem - insert only when not exists

    Hello experts!
    I have a problem with a trigger I'm trying to create. It compiles but I receive an error message when the trigger fires.
    The scenario is as follows:
    I have a table TBL_PUNKTDATEN. Whenever the status for a record in that table is changed to 3 or 4 I need the trigger to insert a dataset into my target table (TBL_ARBEIT_ZU_GEBIET).
    However, the trigger must only insert data when there's no existing record in the target table. The condition that specifies whether there is a dataset or not, is the field LNG_GEBIET, which exists in the source as well as in the target table. Hence, for each LNG_GEBIET there can be only one dataset in the target table!
    I created a trigger using the following code. However it doesn't work.
    Maybe you'll see what I want to achieve when having a look at my code.
    Can you please help me out on this one?
    Thanks a lot!
    Sebastian
    create or replace
    TRIGGER set_status_arbeit_zu_gebiet AFTER
      UPDATE ON TBL_PUNKTDATEN FOR EACH ROW WHEN(new.INT_STATUS=3 or new.INT_STATUS=4)
    declare
        cursor c is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET;
        x number;
    begin
        open c;
        fetch c into x;
        if c%NOTFOUND  then 
        INSERT INTO TBL_ARBEIT_ZU_GEBIET
            LNG_GEBIET,
              LNG_ARBEITSSCHRITT,
              PNUM,
              INT_BEARBEITER,
              DATE_DATUM,
              GEPL_DATUM
            VALUES
            (:new.LNG_GEBIET,
             52,
             1114,
             895,
             sysdate,
             to_date('01.01.1990', 'DD.MM.YYYY')
        end if;
    end;Well, on the first insert the code works properly and inserts the recordset as expected. However, if there is an existing recordset where :new.LNG_GEBIET matches LNG_Gebiet in my target table, I receive the ORA-06502 error!
    Maybe that spcifies it a little bit???
    Hope you can help me!
    Thank you!
    Edited by: skahlert on 23.09.2009 10:26
    Edited by: skahlert on 23.09.2009 10:28

    Thank you very much Peter G!
    That %Rowtype mod did the trick! Great solution! Thanks! The trigger works principally if there wasn't the fact that it fires also when the status of one individual record is 3 or 4.
    I need it to fire only when all records with the same attribute LNG_GEBIET (by the way, you guess was right - it's not a number) are of status 3 or 4.
    Is it possible to use the cursor function for the trigger's when condition?
    Such as:
    declare
        cursor c3 is select COUNT(*) from TBL_PUNKTDATEN where LNG_GEBIET=:new.LNG_GEBIET;and
    declare
        cursor c4 is select COUNT(*) from TBL_PUNKTDATEN where INT_STATUS = 3 and  LNG_GEBIET=:new.LNG_GEBIET or INT_STATUS = 4 and  LNG_GEBIET=:new.LNG_GEBIET;
      And then subsequently somehow compare the results of both cursors?
    ... WHEN c3=c4
    declare
        cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET;
        v_c2  c2%ROWTYPE;
    begin
    open c2;
    fetch c2 into v_c2;
    if c2%notfound then
            INSERT INTO TBL_ARBEIT_ZU_GEBIET
            LNG_GEBIET,
              LNG_ARBEITSSCHRITT,
              PNUM,
              INT_BEARBEITER,
              DATE_DATUM,
              GEPL_DATUM
            VALUES
            (:new.LNG_GEBIET,
             52,
             1114,
             895,
             sysdate,
             to_date('01.01.1990', 'DD.MM.YYYY')
            end if;
            close c2;
    end;Please excuse me if the attempt is simply stupid!
    Sebastian
    Edited by: skahlert on 23.09.2009 15:36
    I just saw your reply Max! Thank you! Now I understand far better! Seems to be a successful day! I'm learning a lot! Will also test that method!
    If we could find a solution to the problem I described above it would make it a perfect day! I'm continously trying different attempts to have the trigger only fire when all records are 3 or 4.
    Not that you think I'm just waiting for your answers! That's not the case!
    Thank you all!
    Edited by: skahlert on 23.09.2009 17:30

  • Problem inserting records in table using cursors

    hi all
    i have a block in which i m trying to take records from a table pass it to a procedure which in turn calls some procedures
    and than the procesed records are dumped into another table
    this is my code
    set serveroutput on
    declare
    lastcall date;
    srcip varchar2(50);
    username varchar2(50):='9204';
    duration number;
    callto varchar2(50);
    accountid varchar2(50);
    calltime date;
    subscriberid varchar2(50);
    country varchar2(50);
    cost varchar2(50);
    CURSOR process_cdr
              IS
    SELECT
              srcip,
              username,
              callto,
              calltime,
              duration
    FROM rawcdr
    WHERE     calltime>lastcall;
    begin
    select max(calltime_gmt) into lastcall from
    processed_cdr;
    open process_cdr;
    fetch process_cdr into srcip,username,callto,calltime,duration;
    dbms_output.put_line(callto);
    if (instr(callto,'00')=5) then
    callto:=SUBSTR(REPLACE(callto,SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') + 3, 50);
    dbms_output.put_line(callto);
    elsif (instr(callto,'011')=5) then
    callto:=SUBSTR(REPLACE(callto, SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') + 4, 50);
    dbms_output.put_line(callto);
    else
    callto:=SUBSTR(REPLACE(callto, SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') +1 , 50);
    end if;
    process_call(srcip,username,duration,callto,accountid,subscriberid,country,cost);
    dbms_output.put_line(cost);
    dbms_output.put_line('trying to insert');
    insert into processed_cdr values(accountid,subscriberid,srcip,username,callto,country,calltime,duration,cost) ;
    dbms_output.put_line('inserted successfully');
    FETCH process_cdr INTO srcip, username, callto, calltime, duration;
    close process_cdr;
    end;
    now the problem is that
    records are not getting inserted nor an error is shown
    i guess i m not that much familiar with cursors
    and thats creating prob
    please help

    Hallo,
    but you haven't a loop ! :-)
    Try this,
    (not tested)
    set serveroutput on
    declare
    lastcall date;
    srcip varchar2(50);
    username varchar2(50):='9204';
    duration number;
    callto varchar2(50);
    accountid varchar2(50);
    calltime date;
    subscriberid varchar2(50);
    country varchar2(50);
    cost varchar2(50);
    CURSOR process_cdr
    IS
    SELECT
    srcip,
    username,
    callto,
    calltime,
    duration
    FROM rawcdr
    WHERE calltime>lastcall;
    begin
    select max(calltime_gmt) into lastcall from
    processed_cdr;
    open process_cdr;
    LOOP
    fetch process_cdr into srcip,username,callto,calltime,duration;
    EXIT WHEN process_cdr%NOTFOUND;
    dbms_output.put_line(callto);
    if (instr(callto,'00')=5) then
    callto:=SUBSTR(REPLACE(callto,SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') + 3, 50);
    dbms_output.put_line(callto);
    elsif (instr(callto,'011')=5) then
    callto:=SUBSTR(REPLACE(callto, SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') + 4, 50);
    dbms_output.put_line(callto);
    else
    callto:=SUBSTR(REPLACE(callto, SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') +1 , 50);
    end if;
    process_call(srcip,username,duration,callto,accountid,subscriberid,country,cost);
    dbms_output.put_line(cost);
    dbms_output.put_line('trying to insert');
    insert into processed_cdr values(accountid,subscriberid,srcip,username,callto,country,calltime,duration,cost) ;
    dbms_output.put_line('inserted successfully');
    /* Second fetch is not needed
    --FETCH process_cdr INTO srcip, username, callto, calltime, duration; */
    END LOOP;
    close process_cdr;
    COMMIT; -- eventually
    end;You didn't answered - do you do COMMIT elsewhere ?
    I placed COMMIT also, if you don't need it, you can comment it
    Regards
    Dmytro

  • When table last updated

    Can i know how to find out/sql query when was the last time oracle table is updated

    If you are interested in the timing of the most recently committed INSERTs and UPDATEs, you can find out the SCN of the most recently modified row in the table using this query
    SELECT max(ORA_ROWSCN)
    FROM <TABLE>Once you have the most recent SCN, you can try to find out what time it corresponds to.
    For “recent” SCNs, you can try SCN_TO_TIMESTAMP function.
    If SCN_TO_TIMESTAMP does not work for your SCN, you can try to approximate the time using V$ARCHIVED_LOG or other methods.
    Again, this procedure would not detect DELETEd records.
    Iordan Iotzov
    http://iiotzov.wordpress.com/

  • Dynamic update  of cursor records when table gets updated

    Hi,
    I am having a table with 4 columns as mentioned below
    For a particular prod the value greater less than 5 should be rounded to 5 and value greater than 5 should be rounded to 10. And the rounded quantity should be adjusted with in a product starting with orderby of rank with in a prod else leave it
    Table1
    Col1     prod     value1     rank
    1     A     2     1          
    2     A     6     2
    3     A     5     3
    4     B     6     1
    5     B     3     2
    6     B     7     3
    7     C     4     1
    8     C     2     2
    9     C     1     3
    10     C     7     4
    Output
    Col1     prod     value1     rank
    1     A     5     1          
    2     A     5     2
    3     A     3     3
    4     B     10     1
    5     B     0     2
    6     B     6     3
    7     C     5     1
    8     C     5     2
    9     C     0     3
    10     C     4     4
    I have taken all the records in to a cursor. Once after rounding the request of 1st rank and adjusting the values of next rank is done. Trying to round the value for 2nd rank as done for 1st rank. Its not taking the recently updated value(i,e adjusted value in rounding of 1st rank).
    This is becoz of using a cursor having a value which is of old value.
    Is there any way to handle such scenario's where cursor records gets dynamically updated when a table record is updated.
    Any help really appreciated.
    Thanks in Advance

    Hi,
    Below is the scenario. Which I am looking for.
    ITEM_ID(A)
    ITEM_ID Value Date
    A          3     D1     
    A          5     D2
    A          3     D3     
    A          5     D4
    A          3     D5     
    A          5     D6
    Rounding for Item A has to be done for the rows less then D2 and rounding value is
    x and value adjustment to be done from very next row.
    --For record D1 rounding to be done and value adjustment is to be done from D2 to till the end untill the adjustment value is 0.
    --For record D2 (updated value has to be taken from rounding which updated in D1 row rounding) and the adjustment has to be done from very next row D3 to till the end or adjustment value is o.
    --For D3 row onwards no rounding has to be done.
    ITEM_ID(B)
    B          7     D1     
    B          8     D2
    B          9     D3     
    B          5     D4
    B          4     D5     
    B          3     D6
    Rounding for Item has to be done for the rows less then D3 and rounding value is
    y and value adjustment to be done from very next row.
    --For record D1 rounding to be done and value adjustment is to be done from D2 to till the end untill the adjustment value is 0.
    --For record D2 (updated value has to be taken from rounding which updated in D1 row rounding) and the adjustment has to be done from very next row D3 to till the end or adjustment value is o.
    --For record D3 (updated value has to be taken from rounding which updated in D2 row rounding) and the adjustment has to be done from very next row D4 to till the end or adjustment value is o.
    --For D4 row onwards no rounding has to be done.
    Thanks in Advance
    Edited by: unique on Apr 16, 2010 11:20 PM

  • Problem inserting rows to table using BPEL workflow

    Hi,
    I’m going to invoke below procedure which is inside a package.
    PROCEDURE as_ebs_status_msg(getData in varchar) AS
    BEGIN
    insert into AS_AP_INV_STATUS_IPM values('BP1234','BP1234','BP1234');
    END as_ebs_status_msg;
    Once I invoke this procedure from sql developer (Using execute command) it inserts those values to the table.
    But when I invoke this from a BPEL work flow (adding partner link) it completes without any error. But values are not getting populated to the table.
    And I tried to use Insert functionality of DB adapter, that is also not inserting values to any table but I can run select queries.
    Is anyone came across this issue?
    Thank You,
    any response greatly appreciated.......
    Edited by: Nir on Aug 31, 2011 10:47 PM

    Hallo,
    but you haven't a loop ! :-)
    Try this,
    (not tested)
    set serveroutput on
    declare
    lastcall date;
    srcip varchar2(50);
    username varchar2(50):='9204';
    duration number;
    callto varchar2(50);
    accountid varchar2(50);
    calltime date;
    subscriberid varchar2(50);
    country varchar2(50);
    cost varchar2(50);
    CURSOR process_cdr
    IS
    SELECT
    srcip,
    username,
    callto,
    calltime,
    duration
    FROM rawcdr
    WHERE calltime>lastcall;
    begin
    select max(calltime_gmt) into lastcall from
    processed_cdr;
    open process_cdr;
    LOOP
    fetch process_cdr into srcip,username,callto,calltime,duration;
    EXIT WHEN process_cdr%NOTFOUND;
    dbms_output.put_line(callto);
    if (instr(callto,'00')=5) then
    callto:=SUBSTR(REPLACE(callto,SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') + 3, 50);
    dbms_output.put_line(callto);
    elsif (instr(callto,'011')=5) then
    callto:=SUBSTR(REPLACE(callto, SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') + 4, 50);
    dbms_output.put_line(callto);
    else
    callto:=SUBSTR(REPLACE(callto, SUBSTR(callto, INSTR(callto, '@'), 50), ''), INSTR(callto, ':') +1 , 50);
    end if;
    process_call(srcip,username,duration,callto,accountid,subscriberid,country,cost);
    dbms_output.put_line(cost);
    dbms_output.put_line('trying to insert');
    insert into processed_cdr values(accountid,subscriberid,srcip,username,callto,country,calltime,duration,cost) ;
    dbms_output.put_line('inserted successfully');
    /* Second fetch is not needed
    --FETCH process_cdr INTO srcip, username, callto, calltime, duration; */
    END LOOP;
    close process_cdr;
    COMMIT; -- eventually
    end;You didn't answered - do you do COMMIT elsewhere ?
    I placed COMMIT also, if you don't need it, you can comment it
    Regards
    Dmytro

  • Problem in translations when Table maintenance screens

    Hi,
    I have generated maintenance for a custom table. I am able to see the sceen title (= Table description) in EN (original langauge).
    However, when I login into other languages it it displaying the screen title as "?".
    Could you please let me know how to translate the screen title?
    Thanks,
    Sandeep

    Hi
    In SE11  Select -> Goto -> Translation -> Select the lang -> enter the conversion text, save and activate
    This is what I have translated
    [DD02T     00001]
    Table Details
    Tabelle Einzelheiten
    When I logged using DE, I am able to see the text.
    Shiva

  • Update form when table is updated

    Hi experts,
    I am quite new to apex and i have come across an issue. I have created a table with 10 columns and from that created a form/report.i have to update my table by adding new columns but i can't get my report updated.
    i have manually included the field in my sql query but tat didnt seem to work.
    is there anywhere i should change to get my form and report updated.your advice would be very appreciated. thanks
    kevin

    Hi,
    Normally, the report would just update automatically to include new columns - usually these are placed at the end of the list of columns. If you edit your report region and click on the Report Attributes tab, do you see your new columns there? If so, is the Show checkbox ticked for them? If it isn't, tick it. If you click on the Edit icon next to a missing column, what "Display As" is set - is it "Standard Report Column"?
    Or, are you using an Interactive Report? If so, you would need to run the page, click the Action icon and then select "Select Columns" and make sure that every column is listed on the right.
    Andy

  • Send email when first record updated problem

    Hi guys i have problem
    this code send email based on timer every 5 minutes
    it working ok but my problem i need to determine first rcord updated not inserted
    and send email this is starting work
    this is my code
    ---timer1_Tick---
    Sales.SalesClass SalesClass1 = new Sales.SalesClass();
    DataTable dt = SalesClass1.ShowSalesData("Data Source=192.168.1.5;Initial Catalog=Altawi-last06-01-2015;User ID=admin;Password=123");
    dataGridView1.DataSource = dt;
    dataGridView1.Refresh();
    namespace Sales
    class SalesClass
    public DataTable ShowSalesData(string ConnectionString)
    SqlConnection con = new SqlConnection(ConnectionString);
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "showsales1";
    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = cmd;
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataTable dt = ds.Tables[0];
    return dt;
    SELECT     ROW_NUMBER() OVER (ORDER BY dbo.[Jeddah-Live$Sales Header].No_) AS [م], dbo.[Jeddah-Live$Sales Line].[Document No_] AS 'رقم الطلب',
    dbo.[Jeddah-Live$Sales Header].[Bill-to Name] AS 'العميل', dbo.[Jeddah-Live$Sales Line].Area AS 'نوع الصبه', dbo.[Jeddah-Live$Sales Line].Description AS 'البيان',
    dbo.[Jeddah-Live$Sales Header].[Pump No_] AS 'المضخه', CAST(ROUND(dbo.[Jeddah-Live$Sales Line].Quantity, 0, 1) AS int) AS 'المطلوب',
    CAST(ROUND(dbo.[Jeddah-Live$Sales Line].[Quantity Shipped], 0, 1) AS int) AS 'المصبوب', CAST(ROUND(dbo.[Jeddah-Live$Sales Line].[Outstanding Quantity], 0,
    1) AS int) AS 'المتبقى '
    FROM         dbo.[Jeddah-Live$Sales Header] INNER JOIN
                          dbo.[Jeddah-Live$Sales Line] ON dbo.[Jeddah-Live$Sales Header].No_ = dbo.[Jeddah-Live$Sales Line].[Document No_] AND
                          dbo.[Jeddah-Live$Sales Header].[Sell-to Customer No_] = dbo.[Jeddah-Live$Sales Line].[Sell-to Customer No_]
    The code above not have any problem and working
    When first record updated send email
    Example to show
    orderno   quantity  shipped quantity
    12            20               0
    13            30               0
    14            25               0
    15           22                0
    suppose order no 14 shipped quantity updated be 10 (meaning 0 be 10
    then send email with starting work
    after this any updated to any record not send
    no problem i dont need any send email code but how to get record updated first

    Hi guys i have problem
    this code send email based on timer every 5 minutes
    it working ok but my problem i need to determine first rcord updated not inserted
    and send email this is starting work
    this is my code
    ---timer1_Tick---
    Sales.SalesClass SalesClass1 = new Sales.SalesClass();
    DataTable dt = SalesClass1.ShowSalesData("Data Source=192.168.1.5;Initial Catalog=Altawi-last06-01-2015;User ID=admin;Password=123");
    dataGridView1.DataSource = dt;
    dataGridView1.Refresh();
    namespace Sales
    class SalesClass
    public DataTable ShowSalesData(string ConnectionString)
    SqlConnection con = new SqlConnection(ConnectionString);
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "showsales1";
    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = cmd;
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataTable dt = ds.Tables[0];
    return dt;
    SELECT     ROW_NUMBER() OVER (ORDER BY dbo.[Jeddah-Live$Sales Header].No_) AS [?], dbo.[Jeddah-Live$Sales Line].[Document No_] AS '??? ?????',
    dbo.[Jeddah-Live$Sales Header].[Bill-to Name] AS '??????', dbo.[Jeddah-Live$Sales Line].Area AS '??? ?????', dbo.[Jeddah-Live$Sales Line].Description AS '??????',
    dbo.[Jeddah-Live$Sales Header].[Pump No_] AS '??????', CAST(ROUND(dbo.[Jeddah-Live$Sales Line].Quantity, 0, 1) AS int) AS '???????',
    CAST(ROUND(dbo.[Jeddah-Live$Sales Line].[Quantity Shipped], 0, 1) AS int) AS '???????', CAST(ROUND(dbo.[Jeddah-Live$Sales Line].[Outstanding Quantity], 0,
    1) AS int) AS '??????? '
    FROM         dbo.[Jeddah-Live$Sales Header] INNER JOIN
                          dbo.[Jeddah-Live$Sales Line] ON dbo.[Jeddah-Live$Sales Header].No_ = dbo.[Jeddah-Live$Sales Line].[Document No_] AND
                          dbo.[Jeddah-Live$Sales Header].[Sell-to Customer No_] = dbo.[Jeddah-Live$Sales Line].[Sell-to Customer No_]
    The code above not have any problem and working
    When first record updated send email
    Example to show
    orderno   quantity  shipped quantity
    12            20               0
    13            30               0
    14            25               0
    15           22                0
    suppose order no 14 shipped quantity updated be 10 (meaning 0 be 10
    then send email with starting work
    after this any updated to any record not send
    no problem i dont need any send email code but how to get record updated first

  • Insert to multiple table using single DB Adapter

    Hi,
    I m using Jdev 11g Build JDEVADF_11.1.1.2.0_GENERIC_091029.2229.5536
    Can anyone tell me how can we do insert and update operations to mutliple tables using single DB adapter.
    I want to do insert in 2 tables and update the third using same DB apater. Is it possible?If yes, how?

    Hi,
    You can write a PL\SQL (Stored Procedure) to do your operations and call the PL\SQL code from DB Adapter.
    -Senaka

  • Problem while update and insert data in table

    Hi All,
    I have problem while save line data....
    I have an advance table.I take remove and duplicate line in message choice of advance table action layout.
    Also there is one temp table to save Po number data which is populated in advance table according to PO Number search.And In Temp table record number is column which use
    to insert and update data in temp table which mention in procedure
    Problem is that : When i Searched PO Number and duplicate line and save that record it insert a new line always and it insert record according to duplicate line no .It not update previous line,insert new line always according to duplicate line no.
    Please tell me what is solution?
    Thanks,
    Neil

    Hi,
    I am not cleared with your requirement.
    If possible send me the screenshots for the same.
    --Sushant
    [email protected]

  • ERROR (ORA-01002)  when Ioading a table by UPDATE/INSERT

    I get the error message ORA-01002 ( Fetch out of sequence ) when I am loading a table by UPDATE/INSERT.
    At de Runtime Audit Viewer the process of loading update a number of register, in that case 44.050 and to the left register I get the error message that I show above.

    Can you please give us some details about your source and targets. I have used UPDATE/INSERT but I did not get this kind of error.
    rgds
    -AP

  • Problem while inserting into a table which has ManyToOne relation

    Problem while inserting into a table *(Files)* which has ManyToOne relation with another table *(Folder)* involving a attribute both in primary key as well as in foreign key in JPA 1.0.
    Relevent Code
    Entities:
    public class Files implements Serializable {
    @EmbeddedId
    protected FilesPK filesPK;
    private String filename;
    @JoinColumns({
    @JoinColumn(name = "folder_id", referencedColumnName = "folder_id"),
    @JoinColumn(name = "uid", referencedColumnName = "uid", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Folders folders;
    public class FilesPK implements Serializable {
    private int fileId;
    private int uid;
    public class Folders implements Serializable {
    @EmbeddedId
    protected FoldersPK foldersPK;
    private String folderName;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "folders")
    private Collection<Files> filesCollection;
    @JoinColumn(name = "uid", referencedColumnName = "uid", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Users users;
    public class FoldersPK implements Serializable {
    private int folderId;
    private int uid;
    public class Users implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer uid;
    private String username;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "users")
    private Collection<Folders> foldersCollection;
    I left out @Basic & @Column annotations for sake of less code.
    EJB method
    public void insertFile(String fileName, int folderID, int uid){
    FilesPK pk = new FilesPK();
    pk.setUid(uid);
    Files file = new Files();
    file.setFilename(fileName);
    file.setFilesPK(pk);
    FoldersPK folderPk = new FoldersPK(folderID, uid);
         // My understanding that it should automatically handle folderId in files table,
    // but it is not…
    file.setFolders(em.find(Folders.class, folderPk));
    em.persist(file);
    It is giving error:
    Internal Exception: java.sql.SQLException: Field 'folderid' doesn't have a default value_
    Error Code: 1364
    Call: INSERT INTO files (filename, uid, fileid) VALUES (?, ?, ?)_
    _       bind => [hello.txt, 1, 0]_
    It is not even considering folderId while inserting into db.
    However it works fine when I add folderId variable in Files entity and changed insertFile like this:
    public void insertFile(String fileName, int folderID, int uid){
    FilesPK pk = new FilesPK();
    pk.setUid(uid);
    Files file = new Files();
    file.setFilename(fileName);
    file.setFilesPK(pk);
    file.setFolderId(folderId) // added line
    FoldersPK folderPk = new FoldersPK(folderID, uid);
    file.setFolders(em.find(Folders.class, folderPk));
    em.persist(file);
    My question is that is this behavior expected or it is a bug.
    Is it required to add "column_name" variable separately even when an entity has reference to ManyToOne mapping foreign Entity ?
    I used Mysql 5.1 for database, then generate entities using toplink, JPA 1.0, glassfish v2.1.
    I've also tested this using eclipselink and got same error.
    Please provide some pointers.
    Thanks

    Hello,
    What version of EclipseLink did you try? This looks like bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=280436 that was fixed in EclipseLink 2.0, so please try a later version.
    You can also try working around the problem by making both fields writable through the reference mapping.
    Best Regards,
    Chris

  • Problem in using JDBC Execute commands(Update & Delete Only) with af:Table

    HI Everyone,
    I have one issue with Updating and Deleting Row Data using JDBC Execute commands.
    Suppose In My Application i have two pages, in Page 1 I have Two Command Buttons(Delete and Save) and One Input TextBox to write the String to be stored in the Database. and Page 2 where the result Table is shown and table is binded with a ViewObject, Now When User Types some String in InTB and click Save then By Programmatically I'm searching, that string is already present in database or not, if it is already exist then Save button converts in Update button and instead of inserting it allows user to Update the String already exist in database.
    Everything is working fine but the problem comes when i put those all buttons on the same page where result table is present.After putting all things on the same page and When i click save button to insert new String it is Successfully inserting but when any of other action is performed like updating or Deleting the existing one.. then my application just hanged and then nothing I able to do.
    Please Help me to understand this problem and give me the solution for this..
    Thanks
    Fizzz...

    Hi frank,
    Thanks to reply me...
    I'm refreshing table's iterator on each command button's action to reflect the changed result... and i'm sorry i mentioned two pages in my project.. actually these are two forms in the same page..which conditionally changed its renderer properties.. its working fine when only one form is renderred and the otherside when both are rendered then it is not working.
    Hope this change will help you to understand the problem.. if something else you are looking for then please tell me..
    Thanks
    Fizzz...

  • Insert one table and update another???

    Hello,
    I was wondering if it is possible to insert a record in one table and update another another record in a different table.
    I have a form on my company's intranet that allows employees to add comments (ADDT Insert transaction) about new products we are going to bring to the market. At the same time, I would like to count the numbers of comments on a particular product and update that number for each product to see which product is getting the most reviews.
    Right now the products are on the homepage with the title and inserted date. From there, the employees click on the product get the info and make comments about it. The problem for me is that I would like to see the comment counts for each product on the home page, which means I would have to update the product table with the count.
    Sorry, I am using PHP as the technology.
    When I used to do it in ASP, I would insert the comment using the POST from the form, but add another hidden field with the count in it and I would use the "Command" Server behavior to retrieve the number and update the other table field.
    I noticed that dreamweaver removed the "Command" server behavior when using PHP.
    All help is greatly appreciated
    Charles.

    Hi Charles,
    you can generally execute queries on a different table using Custom Triggers, and in regards to your "update the product table with the count" scenario the ADDT help file has a helpful pointer in the chapter "Custom transactions and triggers : Save additional information on login" -- in here you´ll find a sample "incremental counter" query which should be easy to adapt.
    Cheers,
    Günter Schenk
    Adobe Community Expert, Dreamweaver

Maybe you are looking for