Insert/Update related tables

Hello,
I am attempting to take XML data - and using a transform, map it to a DB Adapter "merge" (insert if new, update if not) on two related tables. I have set up my db tables as follows...
Table A
ID (unique, primary key)
param1
param2
Table B
ID (foreign key related to Table A - ID)
paramA
There is a "TableA 1:M Table B" relationship set up in the DB as well as in the DB adapter TopLink project.
If I do an initial "merge" (insert), everything works fine - and I get my new record in Table A - and several new related records inserted into Table B (way cool!).
However, if I then try to repeat the merge after modifying something in the incoming data that is associated with Table B data, Table B records associated with that ID all get set to the last instance of Table B data in the input. I know that's confusing - here's an example...
Initial input:
<CAR>
<ID>7</ID>
<param1>Chevrolet</param1>
<param2>Corvette</param2>
<paramA>T-top</paramA>
<paramA>Mag Wheels</paramA>
<paramA>Hood Scoop</paramA>
</CAR>
Resulting Table Data:
Table A:
ID param1 param2
7 Chevrolet Corvette
Table B:
ID paramA
7 T-top
7 Mag Wheels
7 Hood Scoop
Second run with the following input:
<CAR>
<ID>7</ID>
<param1>Chevrolet</param1>
<param2>Corvette</param2>
<paramA>T-top</paramA>
<paramA>Mag Wheels</paramA>
<paramA>Front Hood Scoop</paramA>
</CAR>
Resulting data in DB...
Resulting Table Data:
Table A:
ID param1 param2
7 Chevrolet Corvette
Table B:
ID paramA
7 Front Hood Scoop
7 Front Hood Scoop
7 Front Hood Scoop
I have verified that my XSL transform appears to be working correctly.
Am I using the db adapter "merge" function for something it's not designed to handle (i.e. related tables)? Do I have to code separate update adapter instances to update my related tables individually? I hope not - I was hoping TopLink would just take care of this for me. Maybe I'm too optimistic... ;-)
Thanks for any help!
Lon

Nevermind. I'm an idiot.
Obviously, Table B needs another column to form a unique key - so an update can change just that row. Sorry for wasting your time. :(
Lon

Similar Messages

  • Is there any API to insert/update RA_TERRITORIES table

    Hi
    I have to create diff territory combinations for new customer creation.
    Is there any API for inserting records to RA_TERRITORIES table.
    I did n,t find any thing related to this.
    Thanks&Regards
    RS

    Hi,
    Thanks for the reply,
    But JTF_TERRITORY_PUB is not updating ra_territories table.
    I think its not useful for my purpose.

  • How to find out inserts/updates on table through a query

    Hi All,
    I have huge collection if procedures in my database. when I check the table used by procedures, list appearing is also pretty big.
    Is there a way to find out the inserts/updates into the selected table?
    Please help me out!!!!!!
    Thanks in advance!!
    Regards,
    Srikanth

    SELECT owner, object_type, object_name, object_id, status
      FROM SYS.dba_objects
    WHERE object_id IN (
                       SELECT     object_id
                             FROM public_dependency
                       CONNECT BY PRIOR object_id = referenced_object_id
                       START WITH referenced_object_id =
                                                        (SELECT object_id
                                                           FROM SYS.dba_objects
                                                          WHERE owner = :owner AND object_name = :NAME
                                                                AND object_type = :TYPE))-- Mahesh Kaila

  • Insert/update multiple tables from one form.

    I'm working on an app. that requires the user to fill out a form. The contents from the form is then used to either insert new records or update existing records in multiple tables. Is that possible? Can someone give a details example?

    You should create a form like you would create it having one table. Use row_id as primary key. The rest of the process are done by the triggers - those will take care of updating the right table depending which column was hit.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Insert & update nested table

    Hi
    I have created one nested table with the follwing columns. I have to insert records into the nested table. And also I have to update the nested table. Please find below my table and getting error message.
    Please advose...!!
    SQL> create type details as object(
      2  basic number(7,2),
      3  da number(6,2),
      4  hra number(6,2),
      5  pf number(6,2),
      6  it number(6,2),
      7  gross number(7,2),
      8  ded number(6,2),
      9  net number(8,2));
    10  /
    Type created.
    SQL> create type details_t is table of details;
      2  /
    Type created.
    SQL> ed
    Wrote file afiedt.buf
      1  create table emp_tab(empno number(4),name varchar2(10),details_tab details_t)
      2* nested table details_tab store as empl_details
    SQL> /
    Table created.
    SQL> ed
    Wrote file afiedt.buf
      1* insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null)))
    SQL> /
    Enter value for empno: 1
    Enter value for name: asdf
    Enter value for da: 120
    Enter value for hra: 130
    Enter value for pf: 120
    Enter value for it: 120
    old   1: insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null
    new   1: insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null)))
    insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null)))
    ERROR at line 1:
    ORA-02315: incorrect number of arguments for default constructorCan I use '&' while inserting records into nested table? yes / no ?
    I have to update gross, ded, net columns also..!!
    Please help me..!!
    Regards
    A

    zep@dev>
    zep@dev> create type details as object
          2  (
          3      basic number(7, 2),
          4      da    number(6, 2),
          5      hra   number(6, 2),
          6      pf    number(6, 2),
          7      it    number(6, 2),
          8      gross number(7, 2),
          9      ded   number(6, 2),
         10      net   number(8, 2)
         11  )
         12  /
    Type created
    zep@dev> create type details_t is table of details
          2  /
    Type created
    zep@dev> create table emp_tab(empno number(4),name varchar2(10),details_tab details_t)
          2     nested table details_tab store as empl_details
          3  /
    Table created
    zep@dev> insert into emp_tab
          2  values
          3      (1,
          4       'asdf',
          5       details_t(details(120, 130, 120, 120, 1, 2, 3, 4)));
    1 row inserted
    zep@dev>
    zep@dev>   select *
          2      from table (select details_tab
          3                    from emp_Tab t
          4                   where t.empno = 1);
        BASIC       DA      HRA       PF       IT     GROSS      DED        NET
       120,00   130,00   120,00   120,00     1,00      2,00     3,00       4,00
    zep@dev> -- second object in the same empno = 1
    zep@dev>    insert into table
          2         (select details_tab
          3            from emp_Tab t
          4           where t.empno = 1)
          5     values
          6         (details(200, 230, 220, 220, 10, 11, 12, 13));
    1 row inserted
    zep@dev>
    zep@dev> select *
          2    from table (select details_tab
          3                  from emp_Tab t
          4                 where t.empno = 1);
        BASIC       DA      HRA       PF       IT     GROSS      DED        NET
       120,00   130,00   120,00   120,00     1,00      2,00     3,00       4,00
       200,00   230,00   220,00   220,00    10,00     11,00    12,00      13,00
    zep@dev>
    zep@dev> update table (select details_tab
          2                  from emp_Tab t
          3                 where t.empno = 1)
          4     set gross = nvl(basic,0) + nvl(da,0) + nvl(hra,0),
          5         ded   = nvl(pf,0) + nvl(it,0),
          6         net   = nvl(gross,0) - nvl(ded,0)
          7   where basic = 120;
    1 row updated
    zep@dev>
    zep@dev> select *
          2    from table (select details_tab
          3                  from emp_Tab t
          4                 where t.empno = 1);
        BASIC       DA      HRA       PF       IT     GROSS      DED        NET
       120,00   130,00   120,00   120,00     1,00    370,00   121,00      -1,00
       200,00   230,00   220,00   220,00    10,00     11,00    12,00      13,00
    zep@dev>

  • Insert / update data to a table through DBLINK (oracle)

    I try to insert / update a table from one instance of oracle database to another one through oracle dblink, get following error:
    java.sql.SQLException: ORA-01008: not all variables bound
    ORA-02063: preceding line from MYLINK
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1986)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1144)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2876)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
    The same code to insert / update the exact same table in local instance works fine.No any binding problem. So i am pretty sure all ? mark in SQL are set with some value before sending to Oracle.
    Someone please advise what is possible problem. Db link is not set correctly? or we can not update remote table by dblink.
    By the way i can do insert / update from TOAD to the remote table through DBLINK. Problem happens only in Java code.
    thanks!
    Gary

    dblink links from one database instance to another.
    So it is certainly a source of possible problems when it works on one database and not another.
    You should start by looking at the dblink and it possible testing it in the database not via java.
    Note as well that that error suggests that it is coming from the Oracle database. I believe if you had a bind parameter problem in your java code that the error would come from the driver. But that is a guess on my part.

  • Inserting/updating XML output to tables

    Hi,
    I have a nested XML master details record(2 or 3 table). I want to breaking into different columns and insert/update corresponding table.
    How I parsed in XML.
    Thanks
    Reena

    You need to use extractValue() sql function

  • Updating multiple tables using JDBC Adapter

    Hi,
    I am trying to insert/update multiple tables using one message via JDBC adapter. The following is the message being posted. However, only the first statement was executed. Anything wrong?
    Thanks in advance!
    Hart
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:DeliveryDBUpdate xmlns:ns0="http://test.com/r3_integration"><DeliveryData><DelHeader action="UPDATE_INSERT"><table>DelHeader</table><access><DelNo>0080000230</DelNo><DelType>LF</DelType><XOverwrite>X</XOverwrite><ShipTo>0000000026</ShipTo><SoldTo>0000000026</SoldTo><Priority>00</Priority><DocDate>02/17/2007</DocDate><GText>CIF Test</GText><DelDate>02/20/2007</DelDate><PickDate>02/20/2007</PickDate><ShipPoint>NO02</ShipPoint><PackCount>00000</PackCount></access><key><DelNo>0080000230</DelNo></key></DelHeader>
    <DelItem action="INSERT"><table>DelItem</table><access><DelNo>0080000230</DelNo><ItemNo>000010</ItemNo><GText>10# GRAN-GREAT VALUE</GText><Material>G04410G611</Material><Plant>6005</Plant><SLoc>6005</SLoc><RefDoc>mmenon32</RefDoc><RefItem>00000000</RefItem><DelQty>5.000</DelQty><UOM>BL</UOM></access><access><DelNo>0080000230</DelNo><ItemNo>000020</ItemNo><GText>25# GRAN- GREAT VALUE</GText><Material>G04025G611</Material><Plant>6005</Plant><SLoc>6005</SLoc><RefDoc>mmenon32</RefDoc><RefItem>00000000</RefItem><DelQty>5.000</DelQty><UOM>BG</UOM></access></DelItem></DeliveryData></ns0:DeliveryDBUpdate>

    Hi,
    You need 2 STATEMENT level tags,
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:DeliveryDBUpdate xmlns:ns0="http://test.com/r3_integration">
    <b><DeliveryData1></b>
    <DelHeader action="UPDATE_INSERT">
    <table>DelHeader</table>
    <access>
    <DelNo>0080000230</DelNo>
    <DelType>LF</DelType>
    <XOverwrite>X</XOverwrite>
    <ShipTo>0000000026</ShipTo>
    <SoldTo>0000000026</SoldTo>
    <Priority>00</Priority>
    <DocDate>02/17/2007</DocDate>
    <GText>CIF est</GText>
    <DelDate>02/20/2007</DelDate>
    <PickDate>02/20/2007</PickDate>
    <ShipPoint>NO02</ShipPoint>
    <PackCount>00000</PackCount>
    </access>
    <key>
    <DelNo>0080000230</DelNo>
    </key>
    </DelHeader>
    <b><DeliveryData1></b>
    <b><DeliveryData2></b>
    <DelItem action="INSERT">
    <table>DelItem</table>
    <access>
    <DelNo>0080000230</DelNo>
    <ItemNo>000010</ItemNo>
    <GText>10# GRAN-GREAT VALUE</GText>
    <Material>G04410G611</Material>
    <Plant>6005</Plant>
    <SLoc>6005</SLoc>
    <RefDoc>mmenon32</RefDoc>
    <RefItem>00000000</RefItem>
    <DelQty>5.000</DelQty>
    <UOM>BL</UOM>
    </access>
    <access>
    <DelNo>0080000230</DelNo>
    <ItemNo>000020</ItemNo>
    <GText>25# GRAN- GREAT VALUE</GText>
    <Material>G04025G611</Material>
    <Plant>6005</Plant>
    <SLoc>6005</SLoc>
    <RefDoc>mmenon32</RefDoc>
    <RefItem>00000000</RefItem>
    <DelQty>5.000</DelQty>
    <UOM>BG</UOM>
    </access>
    </DelItem>
    <b></DeliveryData2></b>
    </ns0:DeliveryDBUpdate>
    Try with such a strcuture and let us know if it works.
    Regards
    Bhavesh

  • 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

  • XML PARASE and insert /update in corresponding tables

    Hi,
    I have a XML in which master details tables 3 tables.I want to separate element and insert/update in corresponding tables dynamically.
    Table invlovled in A,B,C
    Thanks
    Reena

    Reena
    The easiest way to do this is along the following lines..
    (1) register an XML Schema that describes the XML you wish to process with theh database.
    (2). create a relational view for the top level elements and for each repeating element (element where maxOccurs > 1 in the XML Schema)
    (3) Use 'insert as select' or other SQL type processing to update your relational tables from the contents of the view
    It is normally recommended that you add the following annotations to the XML Schema before registering it with the database
    (1) At the schema level set xdb:storeVarrayAsTable="true".
    (2) At the complexType level set xdb:maintainDOM="fasle".
    If you search the forum you will find a lot of examples of creating relational views of XML content stored in the XML database. Typically these examples will include key words like 'create or replace view' and 'table(xmlsequence(extract' or 'xmltable'.
    Hope this helps...
    -Mark

  • Insert/Update/Delete in forms6i using Objects table in Oracle9i server

    I am using Oracle 9i server and dev 6i (forms6i).
    i have a form based on Object tables (including REF's items). when i try to insert update, delete the reocrd in the form, it gives error.
    Insert/Update/Delete failed because of OCI_22132: hexadecimal string does not corresopond to a valid REF.
    when i remove REFs items from form (not from database) then it does all functions (insert,update,delete,query).
    Actually i haved used this form with Oracle 8i and it did all functions(insert,update,delete,query). i am using the same tables and types definations in Oracle 9i but it is not working.
    Note: Insert, Update, Delete, or Query is not being done through forms when using REFs items. Others tools like sql*plus are performing the same actions very well.
    Please help.
    I will be thankful to you.
    M. Faisal.

    user563114,
    As James (padders) told you in his reply to a similar question that you posted (Typed tables is treated in the same way as a relational table?) in the Typed tables is treated in the same way as a relational table? forum, the only way you can tell for sure is to try it out both ways, measure and compare the times.
    Of-course, there are many factors that effect the time, apart from whether you use a nested table or a regular table.
    Good Luck,
    Avi.

  • Can not insert/update data from table which is created from view

    Hi all
    I'm using Oracle database 11g
    I've created table from view as the following command:
    Create table table_new as select * from View_Old
    I can insert/update data into table_new by command line.
    But I can not Insert/update data of table_new by SI Oject Browser tool or Oracle SQL Developer tool .(read only)
    Anybody tell me, what's happend? cause?
    Thankyou
    thiensu
    Edited by: user8248216 on May 5, 2011 8:54 PM
    Edited by: user8248216 on May 5, 2011 8:55 PM

    I can insert/update data into table_new by command line.
    But I can not Insert/update data of table_new by SI Oject Browser tool or Oracle SQL Developer tool .(read only)so what is wrong with the GUI tools & why posting to DATABASE forum when that works OK?

  • How to find out who made inserts/updates/deletes made to a SQL Table

    I want to know WHO MAKES INSERTS/UPDATES/DELETES TO a particular SQL Table. Bascially I want to AUDIT ANY Edites made to a SQL 2008 TABLE. I need info such as WHO AMDE THE Updates i.e. the user first/lastname, When update was made, what row was updated etc...How
    can I do that with SQL 2008?

    One way to achieve that would be to use triggers to detect when a change is made to the table, and then insert a record into another table/database detailing what changed and who by.
    You'd need three triggers, one for insert, update and delete respectively, and for each of those you use the "inserted" and "deleted" tables (system tables maintained by SQL) to retrieve what has been done. To retrieve who made the change you can query IDENT_CURRENT
    which returns the last identity value for a specific table.
    See :
    Triggers -
    http://msdn.microsoft.com/en-gb/library/ms189799(v=sql.100).aspx
    Inserted & deleted tables -
    http://technet.microsoft.com/en-us/library/ms191300(v=sql.100).aspx
    INDENT_CURRENT -
    http://technet.microsoft.com/en-us/library/ms175098(v=sql.100).aspx
    There may be better / more up to date ways to do this, but I've used this method successfully in the past, albeit a long time ago (on a SQL 2000 box I think!).

  • Insert,update and delete data in a table using webdynpro for abap

    Dear All,
    I have a requirement to create a table allowing the user to add rows in it and update a row as well as delete a row from that table.To do this I guess I have to make use of ALV.But using ALV I am not able to enter data to a table where as I can make a column editable delete a row etc. please guide me to perform these operations(insert,update and delete) on table.
    Thanks,
    Reddy.

    Hi Sridhar,
    By using ALV you can do all insert delete etc things. if you want to edit i mean you can yenter data in ALV.
    Check this...
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3133474a-0801-0010-d692-81827814a5a1
    Editing alv in web dynpro
    editing rows in alv reports
    Re: editing rows and columns in alv reports in webdynpro abap
    Cheers,
    Kris.

  • What's the best way to insert/update thousands records in multiple tables

    Can anyone give an example of how to insert/update thousands records in multiple tables on performance wise? or what should I do to improve the performance?
    Thanks
    jim

    You can see a set of sample applications in various scenarious available at
    http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/content.html

Maybe you are looking for

  • Solaris 8 installation problem on Dell PowerEdge 500SC

    Hi, I am having TWO PROBLEMS installing Solaris 8 on Dell PowerEdge 500SC. This hardware spec is: Pentium-III at 1GHz 256MB 133MHz ECC SDRAM 20GB 7200RPM ATA100 EIDE hard drive (on integrated ATA-100 controller) 48X EIDE CD-ROM drive (on integrated A

  • How do I change the itunes account to my own account to buy applications?

    I have my sisters account on my itouch and i want to change it to my account and i cant figure out how. please help! thanks

  • My iphone wont restore

    My iphone 4 said it was searching for signal then told me i needed to restore it and once i tried to restore it wouldnt allow me to complete restoring it, so my phone is disable

  • CL_GUI_SPLITTER_CONTAINER

    Is it possible to disable resize of do not display separation line between cells?

  • Run Oracle form non-interactively

    I am using Oracle 8i. I want to be able to run a form non-interactively, that is, in batch mode. The reason for that is that the application is a "turn-key" package and I don't have access to the source. I want to be able to run the form from a UNIX