Joining three tables through link tables

I have three separate tables that are related to each other through two link tables.
Employees have a many to many relationship with Programs (1 link table)
Employee + Programs have a many to many relationship with Attributes (The employee attributes depend on the program). This is another link table.
So, the first link table (emp_prog_lk) has two columns, employee_id and program_id. The second link table has three attributes, employee_id, program_id, and attribute_id.
The question is, how can I map the Employee object so that I can call getAttributes(Program) and receive the list of attributes for the specified program? Is this even possible without writing custom SQL?
Thanks.

How do you want your object model to look? Do you want Employee to simply have a Collection of Attributes? If so, then you're right, I don't think this is possible -- but to me if you'd like this association table between employees and Attributes to have extra info (in this case a Program), then you need to consider and model it in your Object model.
I.e., when you have a relationship table that has anything other than the PK's of the 2 tables it's relating, then you really need to model that in Java and aren't really able to rely on the java.util.Collection to suffice.
- Don

Similar Messages

  • Can't use filter when accessing hana table through link from another table in sapui5

    Hi all,
    Have a strange one and I was wondering if someone had come across this before.
    Hana table structure
          entity SalesOrder {
        key element name : String;
        element contact : Association[0..*] to Contact via backlink order;
    entity Contact {
    element location: Location;
        element order : Association to SalesOrder;
    ==
    each sales order has a number of contacts.
    In javascript, if I bind on list of contacts directly then I can use the filter
    oRowRepeater.bindRows("/Contact",oRowTemplate,null,[new sap.ui.model.Filter("location",sap.ui.model.FilterOperator.EQ, "Germany")]);
    and if I enter link i returns the number of entries
    Contact/$count?$filter=location eq 'Germany'
    But if I get contacts through the sales order it doesn't allow me to use the filter,
    oRowRepeater.bindRows("/SalesOrder('mike')/Contact",oRowTemplate,null,[new sap.ui.model.Filter("location",sap.ui.model.FilterOperator.EQ, "Germany")]);
    I can return the contacts same as accessing them directly and i can get the information such as
    new sap.ui.commons.TextView({text: "{location}"}) same as before but only difference is that i can't filter.
    When I try the following I get error
    /SalesOrder('mike')/Contact/$count?$filter=location eq 'Germany'
    Error
    "message": {
                "lang": "en-US",
                "value": {
                    "type": "ODataInputError",
                    "message": "Bad Request URL: U"
    When I open Chrome Developer Tools I see the following error
    SalesOrder/contact/$count?$filter=location%20eq%20%27EMEA%27 400 (Bad Request)
    Basically the $count doesn't work if you access contacts indirectly even though the link is there.
    Is this a bug or am I doing something wrong?
    Hana is sp8, I am up to date with almost everything.
    Many thanks,
    Matthew

    for the reading/writing from oracle to access, you could do something like this:
    for table in oracle/access with fields of id(number), name(varchar/text):
    Connection oconn = //connect to Oracle
    Connection aconn =  //connect to access
    //create the insert statement into access table
    PreparedStatement apstmt = aconn.prepareStatement("INSERT INTO accesstable (id, name) values (?,?)");
    //select all the results neeed from oracle table
    Statement ostmt = oconn.createStatement();
    ResultSet rs = ostmt.executeQuery("select id, name from oracletable where...");
    while ( rs.next() )
         apstmt.setLong(1, rs.getLong(1));
         apstmt.setString(2, rs.getString(2));
         apstmt.addBatch();
         //if your driver doesn't support batching, just use this:
         //apstmt.executeUpdate();
    //use this only if you use batch statements
    apstmt.executeBatch();
    rs.close();
    stmt.close();
    apstmt.close();
    oconn.close();
    aconn.close();

  • Inserting data into table through linked server

    Hi
    I am trying to insert data from a remote database into my database using linked server.
    Below is the syntax that I am using
    set XACT_ABORT on
    INSERT INTO MyTable
    EXEC [172.xx.xx.xxx].MyDatabase.dbo.[MyStoredProc] '2014-10-20','2014-10-26'  
    When I execute the SP (EXEC [172.xx.xx.xxx].MyDatabase.dbo.[MyStoredProc] '2014-10-20','2014-10-26'   ) I get the result.
    but when I try inserting the data into a table using the above code I get the following error
    OLE DB provider "SQLNCLI11" for linked server "172.xx.xx.xxx" returned message "No transaction is active.".
    Msg 7391, Level 16, State 2, Line 59
    The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "172.xx.xx.xxx" was unable to begin a distributed transaction.
    I tried solutions given on
    http://stackoverflow.com/questions/7473508/unable-to-begin-a-distributed-transaction
    but still i get the issue... I don't know whats wrong.

    I think you may need to set the remote proc transaction promotion for linked server option to
    false.
    Please read the articles in below links for more info:
    How to Share Data between Stored Procedures - The Challenges of Linked Servers (Erland)
    How to insert in table from remote stored procedure without creating a distributed transaction?
    Krishnakumar S

  • How to join three tables and practical difference between 10g and 11g

    I want to know with example how to outer join three different tables in Oracle.
    Also if you have any website or reference for understand syntax or performance difference between 10g and 11g then please paste a link in.thanks!!

    Hi,
    897293 wrote:
    I want to know with example how to outer join three different tables in Oracle.The 3rd table comes into the result set the same way the 2nd one did:
    FROM           table_1  t1
    LEFT OUTER JOIN      table_2  t2  ON   ...
    LEFT OUTER JOIN      table_3  t3  ON   ...The join condition(s) for t3 can reference t1, or t2, or both.
    Also if you have any website or reference for understand syntax or performance difference between 10g and 11g then please paste a link in.thanks!!The main manuals all have "What's New" sections near the beginning. For example:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/wnsql.htm#sthref5
    Hoek,
    We've missed you. Welcome back!

  • ORA-01776: cannot modify more than one base table through a join view

    I have created EO based on a database view than consists of two tables, and only one is updateable.
    When I try to update a row using EO, I got a following message: "ORA-01776-cannot modify more than one base table through a join view"
    In Forms, this issue is resolved by setting "Query Only" property of non-updateable items to "True".
    Is it possible to do something like that in ADF BC?
    Thanks

    Thanks for answer.
    When I set "updateable" property to "Never", that attribute is protected from any change.
    I'm sorry for incomplete usecase.
    I have set up a list of value on that attribute, because it is a lookup field for another table and I need to get an ID from that table.
    Basically, I need that attribute to be updateble for BC, but not for database.
    Edited by: MarioK on Oct 13, 2011 9:28 AM

  • Cannot modify more than one base table through a join view

    hi guys, my current problem is that i have a datablock based on a view, now all the fields bar 1 are updateable, but this one field that is obtained through a join is displayed, the user can enter data in this field which then pupulates other fields which are required, but this specific field should not be updated. Is there an option to state this as i keep getting the error:
    cannot modify more than one base table through a join view
    Any help would be greatly appreciated, thanks.

    the user can enter data in this field which then pupulates other fields So, using the value of "this field" you then query the rest of the fields? Can you show us the code you use to populate the rest of the fields?
    but this specific field should not be updatedHave you tried setting the "Query Only" property of the field to "Yes" and the other DML properties (Ins, Upd, Del) to No?
    Also, what is your Forms version?
    Thanks,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • JOINING local table and DB Link table performance

    Hellou everybody,
    can somebody tell me how it is work in Oracle DB when you want to join some local table and DB Link table for example:
    Select a.col1, b.col2
    from local_table a , remote_table@dblink b
    where a.key = b.key;
    and when I use DRIVING_SITE hint and the all data from remote table is transforming (pushing) into my DB (in some temporar space), it will transform although Indexes from remote table?
    So when I use some JOINS, this joins will be fast enought? Will they using remote table indexes to query the data or not?
    Thank you for response.
    Zoffob

    user10708026 wrote:
    Is it as simple as:No. Use:
    UPDATE  habitationalsupplement live_hab
       SET  primaryheatingapparatuscode = (
                                           SELECT  hab_backup.primaryheatingapparatuscode
                                             FROM  habitationalsupplement@backupdb hab_backup
                                             WHERE hab_backup.itemobjectid = live_hab.itemobjectid
                                               AND hab_backup.itemversionnumber = live_hab.itemversionnumber
      WHERE (itemobjectid,itemversionnumber) IN (
                                                 SELECT  hab_backup.itemobjectid,
                                                         hab_backup.itemversionnumber
                                                   FROM  habitationalsupplement@backupdb hab_backup
    /SY.

  • Joining three tables

    I have to join three tables but i m getting error as given below:
    Error i m getting-
    Syntax error(missing operator) in query expression 'invoice.INVOICE_NO=inv_ent_main.INVOICE_NO INNER JOIN invrate ON invrate.INVOICE_NO=inv_ent_main.INVOICE_N'.
    My Query is-
    "select inv_ent_main.EXPORTER,inv_ent_main.INVOICE_NO,inv_ent_main.INVOICE_DATE,inv_ent_main.BALE_COUNT,inv_ent_main.TOTAL_AMOUNT,inv_ent_main.BALE_COUNT,inv_ent_main.TOTAL_PIECES,inv_ent_main.TOTAL_AREA,invoice.ORDER_NO,invoice.OTHER_REF,invoice.CONSIGN1,invoice.CONSIGN2,invoice.CONSIGN3,invoice.CONSIGN4,invoice.CONSIGN5,invoice.DLV_TERMS,invoice.PAYMENT_TERMS,invoice.PRE_CARRIAGE,invoice.PR_CARRIER,invoice.DESTINATION,invoice.COUNTRY_DESTINATION,invoice.VESS_FLIGHT,invoice.PORT_LOAD,invoice.PORT_DSCH,invoice.MARK1,invoice.MARK2,invoice.CURRENCY,invoice.GOODS_DESCRIPTION,invoice.CFB,invoice.GROSS_WEIGHT,invoice.NET_WEIGHT,invoice.WOOL,invoice.COTTON
    from inv_ent_main INNER JOIN invoice ON invoice.INVOICE_NO = inv_ent_main.INVOICE_NO INNER JOIN invrate ON invrate.INVOICE_NO = inv_ent_main.INVOICE_NO";
    MCA,LUCKNOW.

    The last character in the error message has missing "O" when compare to the actual query you have posted. Please rerun it an verify or you can try the below query. You need to post DDL for all the 3 tables so that we can test.
    select
    inv_ent_main.EXPORTER,
    inv_ent_main.INVOICE_NO,
    inv_ent_main.INVOICE_DATE,
    inv_ent_main.BALE_COUNT,
    inv_ent_main.TOTAL_AMOUNT,
    inv_ent_main.BALE_COUNT,
    inv_ent_main.TOTAL_PIECES,
    inv_ent_main.TOTAL_AREA,
    invoice.ORDER_NO,
    invoice.OTHER_REF,
    invoice.CONSIGN1,
    invoice.CONSIGN2,
    invoice.CONSIGN3,
    invoice.CONSIGN4,
    invoice.CONSIGN5,
    invoice.DLV_TERMS,
    invoice.PAYMENT_TERMS,
    invoice.PRE_CARRIAGE,
    invoice.PR_CARRIER,
    invoice.DESTINATION,
    invoice.COUNTRY_DESTINATION,
    invoice.VESS_FLIGHT,
    invoice.PORT_LOAD,
    invoice.PORT_DSCH,
    invoice.MARK1,
    invoice.MARK2,
    invoice.CURRENCY,
    invoice.GOODS_DESCRIPTION,
    invoice.CFB,
    invoice.GROSS_WEIGHT,
    invoice.NET_WEIGHT,
    invoice.WOOL,
    invoice.COTTON from inv_ent_main
    INNER JOIN invoice ON invoice.INVOICE_NO = inv_ent_main.INVOICE_NO
    INNER JOIN invrate ON invrate.INVOICE_NO = inv_ent_main.INVOICE_NO
    Regards, RSingh

  • How to join THREE different tables into internal table using one select statement .

    How to join THREE different tables into internal table using one select statement .
    Hi experts,
    I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
    Scenario:
    Database tables:
    SPFLI
    SFLIGHT
    SBOOK.
    Table Fields:
    SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
    SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
    SEATSOCC_C SEATSMAX_F SEATSOCC_F
    SBOOK - CARRID CONNID CLASS
    MY INTERNAL TABLE IS IT_XX.
    Your help much appreciated.
    Thanks in advance.
    Pawan.

    Hi Pawan,
    please check below codes. hope it can help you.
    TYPES: BEGIN OF ty_xx,
            carrid     TYPE spfli-carrid   ,
            connid     TYPE spfli-connid   ,
            countryfr  TYPE spfli-countryfr,
            cityfrom   TYPE spfli-cityfrom  ,
            countryto  TYPE spfli-countryto,
            cityto     TYPE spfli-cityto   ,
            fldate     TYPE sflight-fldate ,
            seatsmax   TYPE sflight-seatsmax ,
            seatsocc   TYPE sflight-seatsocc ,
            seatsmax_b TYPE sflight-seatsmax_b,
            seatsocc_b TYPE sflight-seatsocc_b,
            seatsmax_f TYPE sflight-seatsmax_f,
            seatsocc_f TYPE sflight-seatsocc_f,
            class      TYPE sbook-class,
          END OF ty_xx,
          t_xx TYPE STANDARD TABLE OF ty_xx.
    DATA: it_xx TYPE t_xx.
    SELECT spfli~carrid
           spfli~connid
           spfli~countryfr
           spfli~cityfrom
           spfli~countryto
           spfli~cityto
           sflight~fldate
           sflight~seatsmax
           sflight~seatsocc
           sflight~seatsmax_b
           sflight~seatsocc_b
           sflight~seatsmax_f
           sflight~seatsocc_f
           sbook~class
      INTO TABLE it_xx
      FROM spfli INNER JOIN sflight
      ON spfli~carrid = sflight~carrid
      AND spfli~connid = sflight~connid
      INNER JOIN sbook
      ON spfli~carrid = sbook~carrid
      AND spfli~connid = sbook~connid.
    Thanks,
    Yawa

  • How to join three dimension tables

    I have one seperate schema, which consists of only 3 tables(all three tables has dimension fields and fact fields(dim fields =textual fields,fact fields=measures))
    How to handle this type of situation in RPD.
    Ex: table A,Table b,Table c
    Table A needs to join with Table b on many to one relationship.
    Table c needs to join with table b on many to one relationship.
    Anyone suggest me what is the best way to handle this type of situation.do I require to create dimensional hierarchies for all three tables? Or can I consider only table b as dimension and remaining 2 consider as fact?

    This will not be possible. As per dimensional modelling atleast you should have one fact table.
    Dimensional tables can be joined to one another if the have flakes(sightly normalized table).
    so you have start up the things from DWH.
    Regards,
    Kishore.

  • 3 way one-to-many through a single link table

    I have 3 tables that are linked through one to many relationships in a single link table. Here's the real relationships:
    assay(id)
    multiplex(id, assays)
    markerset(id, assays, multiplexes)
    Here's the database schema:
    assay(id, name)
    markerset(id, name)
    multiplex(id, name)
    assay_marker_set(assay_id[not null], marker_set_id[not null], multiplex_id[nullable])
    I've mapped one-to-many relationships between markersets and assays, and multiplexes and assays, and BOTH of these one-to-manys need to be writable. In the record creation process, assays are associated with markersets, and then assays are associated with multiplexes, which in turn are associated with markersets.
    Here's our dilemma. When committing multiplexes through a unit of work, the one-to-many with assays can't see the one-to-many with markersets, so the commit fails because the markerset key is null.
    We've gotten around the problem by creating a postSave() method in markerset that writes multiplex changes once they are created. But again, in a unitofwork commit, saving a markerset fires the postSave() method, which writes assays and multiplexes that have not yet been written to the database.
    We've gotten around THAT by only turning on postSave() when creating multiplexes, not when associating assays with markersets.
    My question is, is there a more conventional approach to this problem? Clearly, the database needs to be reworked, but time constraints and the quantity of data to be curated makes changing the schema impossible. Or have we arrived at the most sensible solution to a ridiculous problem? Currently what we have works, it's just incredibly complicated, and nearly unmaintainable.
    Thanks for the time to even read this post, and mocking is permitted ;-)
    Paul Cooper
    GlaxoSmithKline US Bioinformatics

    Looks like your object model does not match your data model.
    From you object model you seem to have,
    Assay
    MarkerSet 1-m Assay, 1-m Multiplex
    Multiplex 1-m Assay
    From your data model you have,
    Assay 1-m AssayMarkerSetAssociation
    MarkerSet 1-m AssayMarkerSetAssociation
    Multiplex 1-m AssayMarkerSetAssociation
    AssayMarkerSetAssociation 1-1 Assay, 1-1 MarkerSet, 1-1 Multiplex
    (your object model seems to be also missing the name)
    I'm not exactly sure how you have your mapping working, but it would seem the best solution is to introduce an AssayMarkerSetAssociation object into your object model.
    If you do not wish to use this object in your model, you could just use it internally to store the relationship and still have get/set methods for the relationships that you want that initialize themselves from the associations.
    So your object model would be,
    Assay
    MarkerSet 1-m AssayMarkerSetAssociation (+ getAssays, getMultiplexes methods)
    Multiplex 1-m AssayMarkerSetAssociation (+ getAssays, method)
    AssayMarkerSetAssociation 1-1 Assay, 1-1 MarkerSet, 1-1 Multiplex
    In general you seem to be able to get your mapping working without changing your object model, but are probably better off for maintainability to change your model slightly.

  • Code to Join three tables.

    Hi All,
    I am a fresher to this ABAP.
    I have an task to join three tables which doesn't take much effort. But the problem is: the tables have same columns, (name, age and city) in all the three tables.
    The layout is as shown below:
    Table 1  ( T1 )            Table 2  ( T2 )          Table 3 ( T3 )
      name | age | city      name | age | city        name | age | city    -
    Anju   21     HDD      Anju   20     BGH       Anju    21    SFF
    Julie   23     JUH       Julie   24     JUH        Julie   20     JUH
    Now, there should be a selection screen. If I enter a value for this varaible as "Anju", The output should be like:
    Col       T1        T2      T3
    Name    Anju     Anju    Anju
    Age       21        20       21
    City       HDD    BGH    SFF
    I am unable to appraoch how to solve this issue. Any pointers would be of great help.
    Thanks in advance,
    Anjum.
    Edited by: nasarat anjum on Apr 23, 2008 8:43 AM

    Hi,
    U can take three internal tables for each of ur tables T1,T2,T3. Fetch the respective table data into ur internal tables.
    Then write,
    loop at itab1.
    read table itba2 with key name eq itab1-name.
    read table itab3 with key name eq itab1-name.
    write : / name under <name heading>,
                itab1-name under <T1 heading>,
                itab2-name under <T2 heading>,
                itab3-name under <T3 heading>.
    write : / age under <age heading>,
                itab1-age under <T1 heading>,
                itab2-age under <T2 heading>,
                itab3-age under <T3 heading>.
    write : / city under <city heading>,
                itab1-city under <T1 heading>,
                itab2-city under <T2 heading>,
                itab3-city under <T3 heading>.
    <removed by moderator>
    Thanks
    Edited by: Mike Pokraka on Aug 6, 2008 8:30 AM

  • How to join three tables?

    I have used this query to join three tables but it displays an error : field vbak-vbeln is unknown.
    please help me out..
    SELECT vbak-vbeln vbak-bstnk vbap-matnr vbap-zmeng makt-maktx
    INTO CORRESPONDING FIELDs OF TABLE itab FROM vbak
    inner JOIN vbap ON vbak-vbeln eq vbap-vbeln
    inner JOIN makt ON vbap-matnr eq makt-matnr
    WHERE vbak-bstnk = s_bstnk.

    Hi mohan kumar ,
    just follow the Syntax
    SELECT FLD1 FLD2 FLD3 FLD4 FLD5 INTO CORRESPONDING FIELDS OF TABLE ITAB FROM TABLE1 INNER JOIN TABLE2 ON
    TABLE1FLD1 = TABLE2FLD1 INNER JOIN TABLE3 ON TABLE2FLD2 = TABLE3FLD2 INNER JOIN TABL4 ON  TABLE3FLD3 = TABLE4FLD3
    WHERE FLD1 = 'AA'
    Hope this may be helpful.
    Please reward points if found ok.
    Thanks and regards,
    Rajeshwar.

  • Select from multiple tables through dblink

    I am seeking help. Can I select multiple tables through a dblink from a remote database? I tried, it seems it always return ORA-00933 error. code like this:
    select A.ID, B.CODE, C.TYPE_DESC
    from TABLE_ONE A@db_link , TABLE_TWO B@db_link, TABLE_THREE C@db_link;
    where A.ID = B.ID
    and B.CODE = C.CODE
    Thanks in advance.

    Just as an FYI, from a performance standpoint, it is frequently the case (though certainly not guaranteed) that you'll get better performance creating a view on the remote database that does the join of all three tables and to use that view in your query, particularly if you're also joining in local tables. Optimizing SQL statements across database links tends to be particularly hard, a view often helps force Oracle to join the remote tables on the remote database which is generally what you'd want. Of course, this is not a guarantee, and you can always get explicit with hints to force joins to happen on one or the other system, but this is frequently the easiest starting point.
    Justin

  • View for a network node or link table

    Can a view be used for a nework node or link table? The process sdo_net.validate_network hangs when I try to validate a network based on views for the node and link tables.

    I am using a logical model. The sql statement (checking link/node relationship) that hangs is:
    select count(a.link_id) from vlinks a
    where not exists
    select * from vnodes b
    where b.node_id = a.start_node_id or b.node_id = a.end_node_id
    I gather there is a concurrency issue with my links view because it joins a table with itself. I have a link table that has the start and end nodes defined on two records. Here is my view script:
    create or replace view vlinks
    (link_id, link_name, start_node_id, end_node_id, link_type, active, link_level, cost, parent_link_id)
    as
    select a.id, 'Link '||a.id, a.nodeid, b.nodeid, 'simple', 'Y',1,0,''
    from vnodes a, vnodes b
    where a.seq=1 and b.seq>1 and a.id = b.id
    I can create tables from my views and validate them successfully through sdo_net.validate_nodes_schema, sdo_net.validate_links_schema, and sdo_net.validate_network.
    I can analyze the network model through the Java API using the reachable nodes, shortest path, and spanning tree methods without any problems.
    I guess I'll validate my view links by counting the total number of links and subtracting the number of links joined successfully at the start and end nodes - if 0 then all links are valid. E.g.:
    select count(link_id) from
    select link_id from vlinks
    minus
    select a.link_id from vlinks a, vnodes b, vnodes c
    where a.start_node_id = b.node_id
    and a.end_node_id = c.node_id

Maybe you are looking for

  • Diagram Not getting displayed on the Front End UI in SSM 7.5

    Hello , We are running SSM 7.5 SP 04. We uploaded a custom image using diagram manager for the required context in the administration UI. The image is uploaded successfully. But , when I open the strategy tab for my context in the front end UI , I am

  • Question about Time Machine backup on external drive containing photos

    I have a Le Cie external hard drive with iPhoto '08 photos on it.  I bought the drive when I started running out of room on my early 2008 iMac and moved a bunch of iphoto pictures and imovie movies onto it.  Can I use this same external drive to run

  • How to display photo in jsp through blob from oracle

    i am struggling here to retrieve an image which is stored in oracle-blob data type through jdbc-type-1.and i am unable to display that in jsp.i had a rich code library for this problem.but nothing gave me the exact solution. please give me exact the

  • Song Library Management Question

    I have a music library several times larger than my 32gb ipod. My computer recently had a hard drive failure. I reinstalled itunes with everything else. My ipod of course still works. I have about 2750 songs on it. The problem is everything in my lib

  • JTabbedPane switching from within added component

    Hey guys, Anyone know how/if its possible to change between JTabbedPanes by using a button within a component added to one of the Panes? Class A has a JtabbedPane in it and Class B extends JPanel and is added to the TabbedPane as a Component Is there