Complex select query read in Java

I want to use a custom complex select query with join of multiple tables Explicitly to read the object which itself is associated with other object through one-to-many mapping. The objects have been generated through Toplink without Indirection.
The scenario is like this:
Table: Purchase_Order     Object:     PurchaseOrder
2nd Table: Purchase_Order_Line     Object:     PurchaseOrderLine
Relationship is one-to-many between Purchase_Order and Purchase_Order_Line. Corresponding to this, PurchaseOrder has the Collection of PurchaseOrderLine without indirection.
I want to override the internal approach of Toplink by my custom select query to fetch a few attributes only. I tried it in some way but it does not return me PurchaseOrderLine collection.
Please elaborate what should be the approach to run such query in Java using Toplink API?
Thanks in advance!

Could you include the query that you have currently tried.
TopLink 9.0.4 did not support joining 1-m relationships, so this would not be possible, but TopLink 10.1.3 did add this support. You would need to add the 1-m joined attribute to the query to be able to use SQL that joins the 1-m relationship.
In terms of only selecting partial objects, you would need to enable partial object reading on the query to only have some of the object's attributes built, but I believe that 1-m joins are not currently supported for partial object reading.
You may also consider using batch reading on the 1-m in TopLink, as batch reading is more efficient at reading 1-m relationships than joining.

Similar Messages

  • Complex select query

    Hi again!
    Now here's another question...
    I need to make a request to find which rep gave the most rebates to his clients.
    The tables goes as such
    REP *(rep_num*, last name, first name, etc..) <--- CUSTOMER (*customer_num*, last name, first name, rep_num, etc.) <--- ORDERS *(Order_num*, date, customer_num) <---- ORDER_LINE (*Order_num*, Part_num, num_ordered, quoted_price) ----> PART (*part_num*, class, description, price, etc.)
    The rebate is calculated from price-quoted_price.
    Hope it is somewhat clear enough... thanks again!
    Woopsie, sorry about that Tubby!
    Edited by: [email protected] on 11-Feb-2009 11:04
    Edited by: [email protected] on 11-Feb-2009 11:06

    Hi,
    In Tubby's example the WITH clause just mimicks a table called DATA. This is done instead of actually creating such table and then populate it.
    Your error just says that you dont have a column called rebate (as Tubby has). If this doesn't help, then paste your exact query, along with the exact error message. And please enclose everything in {noformat}{noformat} tags to make it readable.
    Regards
    Peter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Splitting complex SQL select query in to independent sequence of small queries.

    =====================
    Problem Description
    =====================
    Consider I have the following table structures with approx no. of records in each.
    Employee Table
    emp_id:
    name :
    dept_id:
    #Approx no. of rows in the table: 1 million
    Department Table
    dept_id:
    dept_name:
    #Approx no. of rows in the table: 1 Hundred
    =====================
    Target Result: is to get the employee name who's id is '100' and the department name he belongs to.
    =====================
    =====================
    Ideal Query : Consider it as COMPLEX QUERY
    =====================
    select emp.name,dept.name
    from     employee emp, department dept
    where      
         emp.dept_id = dept.dept_id
         and
         emp.emp_id = '100';
    =====================
    Optimized Independent Queries : Consider it as SIMPLE QUERIES
    =====================
    Now i want to split the above query in to two independent queries.
    Query #1
    select emp.name
    from     employee emp
    where emp.id = '100';
    :: Returns one row as emp.id is unique.
    Query #2
    select dept.dept_id, dept.name
    from department dept
    :: Returns 100 rows as there are only 100 rows.
    =====================
    Need Your Suggestions Here
    =====================
    If you compare the COMPLEX QUERY against SIMPLE QUERIES, i prefer to use SIMPLE QUERIES, get the results
    and compare department id against two results programmatically and then get the final result. I know the database
    query engines will do similar query optimization like dividing COMPLEX QUERY to SIMPLE QUERIES and run them
    in some specific order to get results faster.
    Now is it possible to get the exact sub queries which the database query engine (ANY database query engine) generates
    out of complex select query? I mean i don't want to do the splitting manually but i still need those sub-queries.
    Can any one help me out please?

    Why on earth would you want to keep the queries separate? As Tom Kyte would say, databases are born to join!
    Providing emp_id has an index on it (and it should, assuming it's the table's primary key!) your "complex" (or, what I would call simple*), it'll most likely be faster than doing it separately. You've not got the context switches for one thing.
    If you want to see what the optimizer does with your query, you should run a trace on the query. An explain plan would give you an idea of what it's going to do, too.
    In general, doing something like this procedurally is going to almost certainly be worse than doing it in SQL (and by worse, I mean slower).
    * I'd hate to see what you'd call some of the monster queries I work with, if you think that query is complex!

  • Select query and read dataset

    i have to read an excel sheet from the application server into an internal table that i hv created.can you help me to write  select query &read dataset statement?
    suppose the internal table name is T_a and it has fields f1 to f7 which are all present in the excel sheet.
    <REMOVED BY MODERATOR>
    Thanks in advance,
    Anand.
    Edited by: Alvaro Tejada Galindo on Feb 14, 2008 2:33 PM

    Hi
    select f1 f2 f3 f4 f5 f6 f7
    from TABLE
    into table T_a.
    read table T_a with key f1 = <val1>.
    <REMOVED BY MODERATOR>
    Regards,
    Mansi.
    Edited by: Alvaro Tejada Galindo on Feb 14, 2008 2:33 PM

  • Parenthesis within a select query.

    I have a doubt as whether i can include Parenthesis within a select query
    as below:-
    SELECT C.CITY_CODE,A.DOCUMENT_TYPE,SUM(A.INSTRUMENT_AMounT) FROM
    ppbs_RECEIPT_HEADER A,ppbs_DISTRIBUTOR_MASTER C WHERE
    A.DISTRIBUTOR_ID = C.DISTRIBUTOR_ID AND
    ( A.STATUS not in( 'CN','BO') or (A.STATUS ='CN' and a.INSTRUMENT_AMOUNT<>a.UNAPPLIED_AMOUNT))
    as we do in a If condition. Please help in solving the doubt as it is urgent.

    No, the result is correct, but is it correct to put the parenthesises around a condition in a normal select query as we do in a 'if' condition or a sub-query. Will the condition in the query be evaluated first and then the other conditions in the normal select query.

  • Doubts in Select query

    Hai,
    I have problem in my select query,
    My previous select query:
      SELECT  rrcty 
            ryear 
            rbukrs
            rzzpspid 
            SUM( hslvt )
            SUM( hsl01 )
            SUM( hsl02 )
            SUM( hsl03 )
            SUM( hsl04 )
            SUM( hsl05 )
            SUM( hsl06 )
            SUM( hsl07 )
            SUM( hsl08 )
            SUM( hsl09 )
            SUM( hsl10 )
            SUM( hsl11 )
            SUM( hsl12 )
            SUM( mslvt )
            SUM( msl01 )
            SUM( msl02 )
            SUM( msl03 )
            SUM( msl04 )
            SUM( msl05 )
            SUM( msl06 )
            SUM( msl07 )
            SUM( msl08 )
            SUM( msl09 )
            SUM( msl10 )
            SUM( msl11 )
            SUM( msl12 )
             FROM zzsl5t
           INTO TABLE it_erbproj
             WHERE rldnr       EQ  c_rldnr        AND
                rrcty      EQ  c_rrcty        AND
                ryear       EQ  v_srr_fyear    AND
                rbukrs      EQ  v_srr_ccode    AND
                racct      EQ  v_racct        AND
                rzzpspid  IN r_zzpspid         
             GROUP BY  RRCTY ryear RBUKRS rzzpspid.
    now i want change the above select query as,
    If user enters input period 03 means,
    i have to select
    SELECT  rrcty 
            ryear 
            rbukrs
            rzzpspid 
            SUM( hslvt )
            SUM( hsl01 )
            SUM( hsl02 )
            SUM( hsl03 )
            SUM( mslvt )
            SUM( msl01 )
            SUM( msl02 )
            SUM( msl03 )
    only, not to select all the periods.
    how can i give fields dynamically.
    please suggest me.
    Elamaran

    Duplicate message. Please close this one and look at my answer Doubt in Select query.

  • Sql Query in Custom Java Class in OIM 9x

    Hi All,
    I m having requirement where I need to execute SQL Select Query in custom java class.
    The class is a action class ,in a method I m trying to execute SQL Query as below
         sdkDataSet = new tcDataSet();
              dataprovider =sdkDataSet.getDataBase();
                   //sdkDataSet = new tcDataSet();
                   sdkDataSet.setQuery(dataprovider, sdkQuery);
                   sdkDataSet.executeQuery();
                   logger.debug(CLASSNAME + methodName + "Query Executed");
                   if (sdkDataSet.getRowCount() > 0)
                        sdkName = sdkDataSet.getString(0);
                        logger.debug(CLASSNAME + methodName+ "The sdkName is " + sdkName);
    Error is returned in logs
    tcDataSetException    Must set a query before executing
    I hope issue is coming due to dataprovider dbrefence.
    Kindly let me know how to execute sql query in a action class.
    Regards,
    Krish

    Hi Pallavi,
    Thanks for your reply...
    OOTB class Name is com.thortech.xl.webclient.actions.ApprovalsAction
    This class will display the pending Approvals for a user.On pending approval page, I need to add one more attribute let say email of the beneficiary user.I have a query which will fetch email value based on RequestID.
    select usr.usr_email from rqu rqu, usr usr, act act  where rqu.usr_key=usr.usr_key and usr.act_key=act.act_key and rqu.req_key=1234*
    Pls let me know if there is any way to get email with or with out executing Query.
    Regards,
    Krish

  • Problem is select query.

    Hello SDNites,
    I have a req where I need to use select query to fetch data. But the conditions which is to be placed in this select query has 3 checkboxes corresponding to the same field. Either of them can be selected at a time. Please let me know how can we put this condition effectively in one select query.
    Thanks,
    Abhishek

    Hi Abhishek,
    Depending on your check box selection u can concatenate the string for where ckause....
    For eg:-
    concatenate `'` 'A' `'` into fs.
    concatenate `'` 'F' `'` into fs1.
    if cb1 = 'X' and CB2 = 'X'.
    CONCATENATE  'bstyp' '='   FS  'OR' 'bstyp' '='  FS1  INTO FS SEPARATED BY SPACE.
    endif.
    select * from dbtab into table itab where (fs).
    depending on ur check box selection u can change ur VARIABLE FS to be used in where clause....... But u just need to use single select query.

  • Select query to read data from a view

    Hi friends,
    We have been using a query to read data from a custom view which used to work perfectly. Now the program sits at that select query forever. We are able to extract same data from se16. Not sure what could be the problem.
    Thanks in advance.

    Dev
    Have a look at the Table Index for the tables involved in the View... I think there is some change in the Indexes.. (Add / Remove / Change)
    Thanks
    Amol Lohade

  • How to use : bind character in DB adapter Select Query SOA11g. Getting Error code :17003 .java.sql.SQLException: Invalid column index error

    Hi All,
    The Actual query to perform is below.
    SELECT name,number from emp  WHERE CASE WHEN :1='T' AND term_date IS Not NULL THEN 1 WHEN :1='A' AND term_date IS NULL THEN 1 WHEN :1='ALL' THEN 1 ELSE  1 END = 1;
    I have tried in DB adapter like below as a parameter for :1 as #vInputParam
    SELECT name,number from emp  WHERE CASE WHEN #vInputParam='T' AND term_date IS Not NULL THEN 1 WHEN #vInputParam='A' AND term_date IS NULL THEN 1 WHEN #vInputParam='ALL' THEN 1 ELSE  1 END = 1;
    Getting Error code :17003 .java.sql.SQLException: Invalid column index error.
    Please suggest me on using ':' bind character in DB adapter Select Query SOA11g.
    Can someone help me on this please?
    Thanks,
    Hari

    Hi,
    Could you please make sure your binding style(Oracle Positional,Oracle named..etc) of the Seeded VO and Custom Vo are same.
    This is the option you will get when you are extending your vo. So make sure that both are same.
    You can refer the below link too
    VO extension leads to "Invalid column index" exception
    Thanks
    Bharat

  • How to write the select query with complex where condition

    Hi all,
    Can u help me in writing  following select query.
    select * from zu1cd_corr where time_stamp between firstday and lastday .
    In the above query time_stamp contains the date and time.
    where as firstday and lastday contains the dates.
    I need to compare the date in the time_stamp with the firstday and lastday.
    But time_stamp contains the time also and it is char of 14 characters length.

    Hi,
    If that is the case u can do as advait specified....
    if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.
    CLEAR : lv_firstday,
                 lv_lastday.
    concatenate firstday '000000' to lv_firstday.
    concatenate lastday '240000' to lv_lastday.
    ranges : r_Date for zu1cd_corr-time_stamp.
    r_date-sign = 'I'.
    r_date-option = 'BT'.
    r_Date-low = lv_firstday.
    r_Date-high = lv_lastday.
    append r_date.
    select * from zu1cd_corr  into table it_zu1cd_corr where time_stamp in  r_Date.
    I hope it helps.
    Regards,
    Nagaraj

  • Query in Select query operation

    Please excuse me for posting this again.
    I'm stuck up with this for 3 days. Lenghty post pls do read and help me.
    How is the select query going to be changed in the SAP so that the original database behind it understands it. I want to know the operation of IN operation in where clause where in we can use ranges.
    I'm asking this because I'm facing a problem using Native SQL.
    Query is like this:
    EXEC SQl.
    OPEN C1 for
    SELECT field1 from table@domain where field2 IN :ABAP_VAR.
    ENDEXEC.
    EXEC SQL.
    FETCH C1 NEXT INTO :VAR1 , :VAR2
    ENDEXEC.
    Oracle usually recognises this statement IN ( '2222' , '3658' , '6895' )
    But here this field that is build dynamically like this is not recognising them as seperate fileds but instead it is taking them as a single string and not selecting anything.
    But if a single value is passed it is fetching the data into the cursor. And the code is working fine.
    Any help in this is highly appreciable.

    "if a in r_range" is is effectively: does the value held in 'a' comply with the values held in range 'r_range'. Ranges can hold NE, patterns etc so this can get quite complex.
    You can see that it is very different from the SQL type IN.
    If your range hold several values you could unstrip it into a string varaible so that it ended up having a value something like: ( '2222' , '3658' , '6895' ). Not sure if you need the '(' but it would be something like this:
    eg,
    assuming your range is simple and only holds 'I' and 'EQ' values:
    data v_string type string.
    loop at r_range.
    concatenate v_string '@''' r_range-low  '''@' into v_string.
    endloop.
    REPLACE
      ALL OCCURRENCES OF '@'
      IN v_string
      WITH ' '.
    Then you can use:
    SELECT field1 from table@domain where field2 IN :v_string.

  • Performance issue with select query and for all entries.

    hi,
    i have a report to be performance tuned.
    the database table has around 20 million entries and 25 fields.
    so, the report fetches the distinct values of two fields using one select query.
    so, the first select query fetches around 150 entries from the table for 2 fields.
    then it applies some logic and eliminates some entries and makes entries around 80-90...
    and then it again applies the select query on the same table using for all entries applied on the internal table with 80-90 entries...
    in short,
    it accesses the same database table twice.
    so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
    is around 80-90 entries too much for using "for all entries"?
    the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
    i really cant find the way out...
    please help.

    chinmay kulkarni wrote:Chinmay,
    Even though you tried to ask the question with detailed explanation, unfortunately it is still not clear.
    It is perfectly fine to access the same database twice. If that is working for you, I don't think there is any need to change the logic. As Rob mentioned, 80 or 8000 records is not a problem in "for all entries" clause.
    >
    > so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
    >
    It is not clear what you tried to do here. Did you try to bring all 20 million records into an internal table? That will certainly cause the program to short dump with memory shortage.
    > the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
    >
    That is fine. Actually, it is better (performance wise) to do much of the work in ABAP than writing a complex WHERE clause that might bog down the database.

  • How to get number of rows return in SELECT query

    i'm very new in java, i have a question:
    - How to get number of rows return in SELECT query?
    (i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
    Thanks.

    make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
             String sql = "select * from testing";
             PreparedStatement ps =
              con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs = ps.executeQuery();
             rs.last();
             System.out.println("Row count = " + rs.getRow());
             rs.beforeFirst();~Tim
    NOTE: Ugly, but does the trick.

  • Problem in the "select" query....Just check out and help me

    Hi there !!
    I am getting the following errors while trying to execute the "select" query from JSP page:
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
    My code is :
    String reg_no=(String)session.getAttribute("reg_no");
    ResultSet rs=stmt.executeQuery("SELECT * FROM reg WHERE regno = "+reg_no);
    (Note: the "regno" in the database is of numeric datatype)
    Try to help me...
    Thanx,
    Ram.

    Just so everyone knows:
    Ram Mohan joined the forum on 7-Sep-2003 and received
    his 25 Dukes for joining.
    Since then, he's posted three questions, each one
    promising 5-10 Dukes, and never once awarded them.
    His strategy seems to be to wave Dukes, ask his
    hit-and-run question, and then bolt.
    Answer his questions if you wish, but don't do it
    expecting Dukes. - MODDuffy, you're getting just as cranky as I have. See what hanging around these forums does to oneself? :)

Maybe you are looking for

  • Going from tiger 10.4.11 to snow leopard 10.6.5

    So for christmas my mom got me an ipod touch(newest one out) and I was completely stoked.To make a long story short,I had to download the new itunes and what happens? I can't because I'm only one os below what is needed.So I am super frustrated becau

  • Different Tax codes in SRM PO and replicate ECC PO

    Hello Experts, Problem related to the TaX code in replicated PO . We are in Extended classic scenario. In SRM, when creating Shopping cart we enter manual tax code like e1(20%) or e2(25%) etc and when PO gets generated and replicated in the backend t

  • IPhoto 6 freezes up requiring force quit - help!

    I loaded all my JPEGs and MPEG4s from my Sony DSCW1 onto 2 DVDS and imported them into iPhoto, creating new albums but keeping the DVDs as the path, ie not copying them to the hard disc. Now iPhoto starts up fine and works for a while but then a mess

  • How to see PDF in the main

    window of ADC? I mean I created protected PDF but they are not visible in ADC. (I am using Acrobat 7)

  • MSS Business Package for R/3 4.6C

    Hi, We have SRM running on Enterprise Portal using WAS 6.2.  We also have our R/3 ver 4.6c which houses our HR system.  My question is: Is it possible to implement MSS on the portal through the SRM using 4.6c as the backend database? If yes, which Bu