Joins in Toplink

Hi All,
I'm new to work with toplink and I'm working with DatabaseQueries,
My requirement is, i need to build an Expression as following the sql query represent
SELECT A.COLUMN_NAME1,A.COLUMN_NAME2, B.COLUMN_NAME3,B.COLUMN_NAME4 FROM TABLE1 A, TABLE2 B
WHERE A.COLUMN_NAME1=B.COLUMN_NAME1;
is it possible to build an expression like this.
how can we overcome this situation.
i tried it but i couldn't get it. My code is:
ReportQuery query = new ReportQuery(Dept.class,builder);
          query.get("deptno").get("empname"));
My database table attributes are
DEPT: deptno(primarykey),dname,location,division;
EMPLOYEE: empno(primarykey), empname,deptno(foreignkey),salary,job;
how can i use joins here.
please suggest me.
sample code is always welcome.
Thanks in advance,
regards
Satish Dasari

Hi Mr jsutherl,
Here I'm posting My code and the error that I'm getting.
I hope this can help me out to get the result using joins.
I'm using JDeveloper 10g 10.1.3.1.0 and Oracle TopLink - 10g Release 3 (10.1.3.1.0)
Session session = getSessionFactory().acquireSession();
try {
ExpressionBuilder builder = new ExpressionBuilder(Emp.class);
Expression expression = builder.getAllowingNull("Dept").get("dname");
ReadAllQuery query = new ReadAllQuery(Emp.class);
query.addJoinedAttribute("dname");
query.setSelectionCriteria(expression);
query.setReferenceClass(Emp.class);
List<Emp> emp = (List<Emp>)session.executeQuery(query);
System.out.println("emp : "+emp);
catch (Exception e) {
System.out.println("error.........jointest: "+e);
session.release();
The Error is
[TopLink Warning]: 2007.01.21 04:34:48.816--ClientSession(12528403)--Exception [TOPLINK-6015] (Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)): oracle.toplink.exceptions.QueryException
Exception Description: Invalid query key [
Query Key dname
Base com.prapansol.tldbqdl.model.Emp] in expression.
Query: ReadAllQuery(com.prapansol.tldbqdl.model.Emp)
07/01/21 16:34:48 error.........jointest: Exception [TOPLINK-6015] (Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)): oracle.toplink.exceptions.QueryException
Exception Description: Invalid query key [
Query Key dname
Base com.prapansol.tldbqdl.model.Emp] in expression.
Query: ReadAllQuery(com.prapansol.tldbqdl.model.Emp)
I unable to check where I'm going wrong. please help me.
Thanks,
regards,
Satish

Similar Messages

  • Joins with Toplink  : Strange Problem!

    Hi!
    I'm trying get the data from EMP table where the column mgr (ValueHolderInterface instance in Toplink POJO) is a self referential key to the empno.
    Now I want to execute a query like this :
    SELECT t0.EMPNO, t0.ENAME, t0.JOB , t0.MGR FROM EMP t0, EMP t1 WHERE (t1.EMPNO = t0.MGR);
    And I used ReportQuery to get this ;
    see the following code
    Session session = getSessionFactory().acquireSession();
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression expression = builder.get("mgr").get("empno").equal(builder.get("empno") );;
    ReportQuery query = new ReportQuery(Emp.class,builder);
    query.addAttribute("empno");
    query.addAttribute("ename");
    query.addAttribute("job");
    query.addAttribute("mgr",builder.get("mgr").get("empno"));
    query.addAttribute("mgr",expression);
    query.dontMaintainCache();
    List<ReportQueryResult> results = (List<ReportQueryResult> )
    session.executeQuery(query);
    And the Toplink Generated SQL is :
    SELECT t0.EMPNO, t0.ENAME, t0.JOB, t1.EMPNO FROM EMP t0, EMP t1 WHERE (t1.EMPNO = t0.MGR)
    which is almost similar.
    But I'm getting an exception as below:
    Exception [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: ORA-00904: "T0"."MGR": invalid identifier
    Error Code: 904
    Further ,
    I tried to get the data from multile tables as below:
    The intended SQL :
    SELECT E.EMPNO,E.ENAME,E.JOB,E.MGR,E.SAL,E.DEPTNO,D.DNAME,D.LOC FROM EMP E, DEPT D WHERE E.DEPTNO=D.DEPTNO;
    And for this I wrote the code as below :
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression expression = builder.get("dept").get("deptno").equal( builder.get("dept").get("deptno"));;
    ReportQuery query = new ReportQuery(Emp.class,builder);
    query.addAttribute("empno");
    query.addAttribute("ename");
    query.addAttribute("job");
    //query.addAttribute("mgr",builder.get("mgr").get("empno"));
    // query.addAttribute("mgr");
    query.addAttribute("ename");
    query.addAttribute("sal");
    query.addAttribute("deptno",builder.get("dept").get("deptno"));
    //query.addAttribute("dept",expression);
    query.addAttribute("dname",builder.get("dept").get("dname"));
    query.addAttribute("loc",builder.get("dept").get("loc"));
    query.dontMaintainCache();
    //query.addAttribute("mgr",expression);
    List<ReportQueryResult> results = (List<ReportQueryResult> ) session.executeQuery(query);
    And the Query Generated by the Toplink is :
    SELECT t0.EMPNO, t0.ENAME, t0.JOB, t0.ENAME, t0.SAL, t1.DEPTNO, t1.DNAME, t1.LOC FROM EMP t0, DEPT t1 WHERE (t1.DEPTNO = t0.DEPTNO);
    which is perfect .
    But the Toplink error message is :Internal Exception: java.sql.SQLException: ORA-00904: "T0"."SAL": invalid identifier
    Error Code: 904
    And I tried to do this using ReadAll Query as below :
    The code I wrote is :
    ExpressionBuilder builder =new ExpressionBuilder();
    // Expression expression = builder.get("");
    ReadAllQuery query = new ReadAllQuery(Emp.class,builder);
    query.addJoinedAttribute("dept");
    query.dontMaintainCache();
    List results = (List) session.executeQuery(query);
    The Toplink Generated SQL is :
    SELECT t1.EMPNO, t1.ENAME, t1.JOB, t1.HIREDATE, t1.EMPDET, t1.SAL, t1.COMM, t1.DEPTNO, t1.MGR, t0.DEPTNO, t0.DNAME, t0.LOC FROM DEPT t0, EMP t1 WHERE (t0.DEPTNO = t1.DEPTNO)
    And the error is :
    Internal Exception: java.sql.SQLException: ORA-00904: "T1"."MGR": invalid identifier
    Error Code: 904
    What mistake am I making ?
    The generated SQL from the Toplink is working fine, I tested it.. but the Strange error message given are puzzling me..
    Could anyone point me where I'm wrong ?
    Thanks in advance,
    Samba.

    Looks like you were trying to use the attributes being returned to define the query's selection criteria.
    To find self-reference manager's in our shipped Employee example I can use:
            ExpressionBuilder eb = new ExpressionBuilder();
            ReportQuery rq = new ReportQuery(Employee.class, eb);
            rq.addAttribute("id");
            rq.addAttribute("firstName");
            rq.addAttribute("lastName");
            rq.setSelectionCriteria(eb.get("manager").get("id").equal(eb.get("id")));
            List<ReportQueryResult> results = (List<ReportQueryResult> ) session.executeQuery(rq);
        }and the generated SQL is: (note: multi-table mapping sith SALARY in use)
    SELECT t0.EMP_ID, t0.F_NAME, t0.L_NAME FROM SALARY t3, EMPLOYEE t2, SALARY t1, EMPLOYEE t0 WHERE (((t2.EMP_ID = t0.EMP_ID) AND (t1.EMP_ID = t0.EMP_ID)) AND ((t2.EMP_ID = t0.MANAGER_ID) AND (t3.EMP_ID = t2.EMP_ID)))If you also add a direct query-key for the manager's id ('managerId') we can avoid the self join:
            ExpressionBuilder eb = new ExpressionBuilder();
            ReportQuery rq = new ReportQuery(Employee.class, eb);
            rq.addAttribute("id");
            rq.addAttribute("firstName");
            rq.addAttribute("lastName");
            rq.setSelectionCriteria(eb.get("managerId").equal(eb.get("id")));
            List<ReportQueryResult> results = (List<ReportQueryResult> ) session.executeQuery(rq);And the SQL looks like:
    SELECT t0.EMP_ID, t0.F_NAME, t0.L_NAME FROM EMPLOYEE t0, SALARY t1 WHERE ((t0.MANAGER_ID = t0.EMP_ID) AND (t1.EMP_ID = t0.EMP_ID))Cheers,
    Doug

  • Equivalent to "Use Joining" of TopLink in EJB3?

    Hi,
    In order to optimize querys of related objects in EJB3 (or JPA):
    Exists some mapping option equivalent to the Join Reading (“Use Joining” check box in JDeveloper 10g R3) of TopLink 10.1.3?
    Thans for your help.
    Regards.

    repost

  • Using joins In toplink

    Hi.I'm using toplink with JSF in Jdeveloper.I want to retrieve data by which uses joins between various tables and and then display it in a datatable.how can I do this??Also,I want scrolls in the datatable with one column fixed and the rest of the columns scrollable.How can I do this?

    To specify joins within your TopLink query in 10.1.3 JDeveloper and earlier you will need to use some customization code ( a descriptor after-load) to set the joining through code. This will be declaratively available a future release.
    To have your data table include columns from related entities you can add columns to the table and use the expression language to access values from related objects.
    Doug

  • How to Join in TopLink

    Hi,
    This is maybe dummy question, but i don't have idea how i can do this.
    Basicly we can view data from database table easly using ADFand EJB-TopLink.
    For example (using HR schema, employee and department table) we can drag employee datacontrol into ADF readonly table.
    But what about if i want to view department name in one table ?
    In short, my problem is similiar like join employee and department table and show the result using ADF table.
    Best Regards
    YM : callme_harry
    Blog : http://harry-christian.blogspot.com

    I think you picked up the wrong department field - you need to pick the department that is under the Employees object.
    Here is the code in my JSF
                <af:table value="#{bindings.Employees.collectionModel}" var="row"
                          rows="#{bindings.Employees.rangeSize}"
                          emptyText="#{bindings.Employees.viewable ? 'No rows yet.' : 'Access Denied.'}"
                          fetchSize="#{bindings.Employees.rangeSize}"
                          selectedRowKeys="#{bindings.Employees.collectionModel.selectedRow}"
                          selectionListener="#{bindings.Employees.collectionModel.makeCurrent}"
                          rowSelection="single">
                  <af:column sortProperty="commissionPct" sortable="true"
                             headerText="#{bindings.Employees.hints.commissionPct.label}">
                    <af:outputText value="#{row.commissionPct}">
                      <af:convertNumber groupingUsed="false"
                                        pattern="#{bindings.Employees.hints.commissionPct.format}"/>
                    </af:outputText>
                  </af:column>
                  <af:column sortProperty="employeeId" sortable="true"
                             headerText="#{bindings.Employees.hints.employeeId.label}">
                    <af:outputText value="#{row.employeeId}">
                      <af:convertNumber groupingUsed="false"
                                        pattern="#{bindings.Employees.hints.employeeId.format}"/>
                    </af:outputText>
                  </af:column>
                  <af:column sortProperty="firstName" sortable="true"
                             headerText="#{bindings.Employees.hints.firstName.label}">
                    <af:outputText value="#{row.firstName}"/>
                  </af:column>
                  <af:column sortProperty="salary" sortable="true"
                             headerText="#{bindings.Employees.hints.salary.label}">
                    <af:outputText value="#{row.salary}">
                      <af:convertNumber groupingUsed="false"
                                        pattern="#{bindings.Employees.hints.salary.format}"/>
                    </af:outputText>
                  </af:column>
                  <af:column sortProperty="departmentName" sortable="true"
                             headerText="#{bindings.Employees.hints.departments.departmentName.label}">
                    <af:outputText value="#{row.departments.bindings.departmentName.inputValue}"/>
                  </af:column>
                </af:table>

  • Toplink outer join issue using ExpressionBuilder getAlllowingNull

    I am trying to retrieve some records through a Toplink outer join expression using ExpressionBuilder's getAllowingNull() with an IN clause but I don't get the correct results.
    In my setup I have the following structure
    CREATE TABLE BOX
    MY_BOX_ID NUMBER(10) PRIMARY KEY
    , MY_CODE VARCHAR2(30) NOT NULL CONSTRAINT u_code UNIQUE
    CREATE TABLE ITEM
    MY_ITEM_ID NUMBER(10) PRIMARY KEY
    ,MY_TYPE NUMBER(6) NOT NULL
    ,BOX_ID REFERENCES BOX(MY_BOX_ID)
    INSERT INTO BOX values (1, '001');
    INSERT INTO ITEM values (1, 1, 1);
    INSERT INTO ITEM values (2, 1, null);
    The Toplink mappings are the most common ones and the code that retrieves the results is
    Vector vals = new Vector();
    vals.add(new String('001'));
    Vector dbList = null;
    try
    DatabaseSession dbSession = getToplinkSession();
    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(Item.class);
    ExpressionBuilder expBuilder = new ExpressionBuilder();
    Expression exp = expBuilder.getAllowingNull("Box").get("myCode").in(vals);
    query.setSelectionCriteria(exp);
    dbList = (Vector) dbSession.executeQuery(query);
    catch(Exception e)
    e.printStackTrace();
    When I run the piece of code Toplink generates the following DB query
    SELECT t1.MY_ITEM_ID, t1.MY_TYPE FROM BOX t0, ITEM t1 WHERE ((t0.MY_CODE IN ('001')) AND (t0.MY_BOX_ID (+) = t1.BOX_ID))
    which returns just the record for which the foreign key is not null
    MY_ITEM_ID MY_TYPE
    1 1
    However I would have expected to get back two records including the one where the foreign key box_id is null. That have happened if the generated SQL would have been:
    SELECT t1.MY_ITEM_ID, t1.MY_TYPE FROM BOX t0, ITEM t1 WHERE ((t0.MY_CODE (+) IN ('001')) AND (t0.MY_BOX_ID (+) = t1.BOX_ID))
    with the outer join operator applied to the query key as well.
    I was wondering if someone could provide some advice on how to get the correct result.
    Thanks for any help,
    Lucian

    Hello,
    Calling builder.getAllowingNull("name_of_field_in_MyJDO"); returns an expression that is not used anywhere in the following code, and so it is not used in the query.
    The addJoinedAttribute(String) on ReadAllQuery will make a simple join expression using the String as the query key. If you want to use an outerJoin instead of the simple inner join created, try:
    readAllQry.addJoinedAttribute(builder.getAllowingNull("name_of_field_in_MyJDO"));
    instead. You will also want to remove any joining statements added at the mapping level made in trying to get this to work, otherwise the inner join specified though those options will still be used.
    Best Regards,
    Chris

  • Named Query (JOIN query) runs in Toplink JPA but not in EclipseLink

    I have a namedquery in JPA entities like (Entities do not include JOIN colums specifically.. no many-to-many or one-to-many relation in entities)
    select a from table1 a, table2 b where a.id=b.id
    This named query runs on Toplink Essentials without any problem.
    When I run this query using EclipseLink
    EclipseLink generates the query below and gives an error.
    select table1.id, table1.name, table1.surname from table1 t0, table2 t1 where t0.id=t1.id
    There are error _"*table1.surname*"_ is invalid identifier. Because; table1 is not define as an alias, must be "t0.surname".
    How can I solce this problem.
    The code runs on Toplink Essential but not in EclipseLink

    I have a namedquery in JPA entities like (Entities do not include JOIN colums specifically.. no many-to-many or one-to-many relation in entities)
    select a from table1 a, table2 b where a.id=b.id
    This named query runs on Toplink Essentials without any problem.
    When I run this query using EclipseLink
    EclipseLink generates the query below and gives an error.
    select table1.id, table1.name, table1.surname from table1 t0, table2 t1 where t0.id=t1.id
    There are error _"*table1.surname*"_ is invalid identifier. Because; table1 is not define as an alias, must be "t0.surname".
    How can I solce this problem.
    The code runs on Toplink Essential but not in EclipseLink

  • TopLink JPA join problems.

    I need a bit of help here, I hope someone can give me a few pointers...
    I've been building out an Object Relational mapping in TopLink using the bean-style interfaces. On one of my objects I have a 1:M relationship to another table, so
    One Key in T1 -> >1 Keys in T2.
    Pretty simple really. I'm doing it like this:
    @JoinTable( name=, etc. etc.)
    private Set<ObjectForTable2> variableName.
    When I call the getVariableName() method, I get back an IndirectSet (as a set) from the method as expected; however, the size of this set is either 0 or 1.
    In Table 2 I have approximately a dozen rows which correspond to the join key, and when I run the query toplink is building in my SQL shell, I get back the dozen rows. When TopLink does it, I only get to see the first row. Is there some other trick I need to use with the set returned? Right now when I call mySet.size() on the Set returned from getVariableName() I get a size of 1 or 0. (I only get 0 if I change the key to one that does not exist in table 2.)
    if I use the iterator method, such as
    for ( final Iterator i = mySet.iterator(); i.hasNext(); ) {
    ObjectForTable2 myObj = (ObjectForTable2)i.next();
    System.out.println( myObj.getXXX() );
    I still only get one result out. Help! What am I doing wrong here? Do I need to configure something to pull back more than one record from the database?
    Also, how does one use the Oracle bugtracker for this open-source product, if I don't have a service contract?
    Thanks,
    Robbie

    Exactly.
    In TopLink (and in JPA in general) you need identify the field, or combination of fields that are used to uniquely identify entities. As Doug mentioned, it is most common that these fields are the PK of the database.
    Based on your response above I assume that you had a non unique field mapped as the PK of the enitity. This could cause the trouble you are experiencing. Mapping the pk to a unique field (or combination of fields) will likely solve this problem.

  • Expression Join TopLink

    Hello,
    I'm having problems doing a join with a TopLink expression.
    I am using two tables, and I have the two classes corresponding to these tables.
    Also the Java Client file for both Java classes.
    In the first Java client (BosetudeClient.java) I have this expression :
         ExpressionBuilder bose = new ExpressionBuilder();
         Expression exp = bose.get("betEorIs").like("1318");
         Vector objects = session.readAllObjects(jsftoplink.model.Bosetude.class,exp);
         return objects;
    It returns me in a datatable the correct rows according to this expression.
    Now, I want to use a join (and an expression) that links the primary key of a table and the foreign key of the second table.
    Do I have to code in the BosetudeClient.java or in the second Client.java file?
    How can I call multiple classes in the session.readAllObjects()?
    Thank you.

    You need what is called a parallel expression. The TopLink 9.0.4 documentation describes parallel expressions in section 6.2.1.4.2 of the query building basics chapter.
    I am assuming you have a User object mapped to your user table.
    User would have fields
    id, type, name, group
    You could write an expression that looked something like this:
    ExpressionBuilder user1 = new ExpressionBuilder();
    ExpressionBuilder user2 = new ExpressionBuilder(User.class);
    Expression exp = user1.get("group").equal(user2.get("group"));
    exp = exp.and(user1.get("type").equal(1));
    exp = exp.and(user2.get("name").equal("bar"));

  • How to use join queries with toplink

    Hi there
    I'm using toplink within the JDeveloper 10.1.3.3. with great success.
    Now, I need to query multiple tables using a join SQL.
    How do you configure toplink now without creating database views?
    I could not find an easy with within the JDev IDE or from google search.
    Any help please?
    Thanks
    Henkie

    In a TopLink query you can query across any relationship to another object. You can also join or batch read the object's relationship using the ObjectLevelReadQuery and ReadAllQuery API (see TopLink documentation).
    You can also map a class to multiple tables.
    -- James : http://www.eclipselink.org

  • Does Toplink support PL/SQL storedProcedure (cursor + join operation)

    Hi,
    Context:- There are two table with relation (Emp, Dept). I am getting data from both table by using Join opeation.
    I am working on Toplink storedProcedureCall and want to get PL/SQL Cursor + join operation
    for example:- select d.dname,e.ename,e.sal from emp e, dept d where e.deptno=d.deptno;
    it's working fine but, when I am dragging DataControl on Form it's only showing EMP attribute but, I need to both EMP,DEPT attribute so that I can display ADF readonly Table control.
    please, help me out. Thanking You.
    regards,
    sufi

    Hello Adilz,
    You seem to have posted a number of times trying to get cursors to work. Cursors do work, and in this case it looks like your stored proc is not working because the procedure you are calling does not accept any output variables - hence the error stating the wrong number of arguments.
    Try defining read_emp and ename in your stored procedure definition in the database.
    Best Regards,
    Chris

  • Outer Join logic

    The following code is an example of how to perform an outer join, in this case with ReportQuery (thanks Doug):
            ExpressionBuilder eb = new ExpressionBuilder();
            ReportQuery rq = new ReportQuery(Employee.class, eb);
            rq.addAttribute("firstName");
            rq.addAttribute("lastName");
            rq.addAttribute("areaCode", eb.anyOfAllowingNone("phoneNumbers").get("areaCode"));
            List<ReportQueryResult> results =  (List<ReportQueryResult>) session.executeQuery(rq);My question is about the logic Toplink uses to generate the outer join statement with the "(+)" in the generated sql.
    Does Toplink only generate the join statement if the same attribute is chosen in the select statement (in the above example "areaCode")?
    Along the same line of questioning, does it matter which attribute was in the get() call? So, in the above example did it have to be areaCode, or could it have been any other attribute of phoneNumber, and it still would have performed the join?
    In my case, because the selection attributes are built up dynamicly, should I add all attributes of my child class (my equivalent PhoneNumber class)?

    Thanks for your reply Doug.
    One last question, hopefully.
    I have a parent table with 2 child tables. When attempting an outer join with both, toplink does not attempt to outer join either. I understand why, sort of - as you get an error when attempting this in sqlplus with "(+)" syntax.
    I understand that you can outer join > 1 other table to a parent with ansi sql syntax:
        select dept.*,emp.*
        from dept left outer join emp
        on dept.deptno = emp.deptnoWill toplink allow > 1 child table outer join to a parent table?

  • Using join and batch reading in the same query

    Hi,
    I wonder if it is possible to use "Joining" and "batch reading" in the same query.
    For example I Have
    A -> 1-1 B
    A -> 1-1 B
    B -> 1-M C
    This is the case where I have two separate 1-1 relationships to the same class B from A. Toplink 10.0.3 can manage it nicely through joining.
    Now, I would like to read a set of As (with its 2 Bs) and all Cs for each B.
    It seems that the following configuration does not work:
    A -> 1-1 B (use joining)
    A -> 1-1 B (use joining)
    B -> 1-M C (Batch read)
    Any help would be greatly appreciated
    Tony.

    James,
    Would you be so kind to look at the following code?
    Am I formulating it correctly to achieve my desired behavior?
    Trip.class -> 1-1 PickupStop
    Trip.class -> 1-1 DropoffStop
    PickupStop and DropoffStop extend Stop and use same table (STOP)
    Stop -> 1-M StopEvents
    I would like to fetch all Trips, with their Stops and all StopEvents in 2 queries:
    1. Trip joined with Stop
    2. Batchread StopEvents
    Code:
    ReadAllQuery raq = new ReadAllQuery(Trip.class);
    Expression qexp1 = new ExpressionBuilder();
    Expression qexp2 = new ExpressionBuilder();
    raq.addJoinedAttribute("pickupStop");
    raq.addJoinedAttribute("dropoffStop");
    raq.addBatchReadAttribute(qexp1.get("pickupStop").get("vStopEvents"));
    raq.addBatchReadAttribute(qexp2.get("dropoffStop").get("vStopEvents"));

  • Problem with outer joins and the class indicator/discriminator

    Hello,
    I am having a problem defining a query in toplink (10.1.3.3).
    In the workbench, I have created a parent and 2 child descriptors. The parent is "AbstractValue", the children are "DefaultValue", classified by the discriminator 'DEF', and "OverrideValue", classified by 'OVR', both located in the same table.
    Another descriptor (containing a one-on-one mapping to both a "DefaultValue", and a "OverrideValue") needs to be queried for its 'value'.
    The way the query should act is: If an override value (row) exists, this one applies for that object. If an override doesn't exist, return the default value.
    The query then comes down to (as I have it now):
    builder.getAllowingNull("OverrideValue").getAllowingNull("value").ifNull(builder.get("DefaultValue").get("value")).equal(builder.getParameter(VALUE_PARAM));
    The problem is that toplink adds the distinction for the different kind of "values" in the where clause WITHOUT checking for null values e.g. it performs an outer join, but then still checks for the discriminator value thus
    ....t1.ovr_id = t2.id(+) AND t2.discriminator = 'OVR' AND ...
    instead of
    ... LEFT JOIN values t2 ON (t1.ovr_id = t2.id AND t2.discriminator = 'OVR') ...
    This leads to the behaviour that the query returns ONLY the objects that have override and default values.
    An overview of the queries (simplified)
    Toplink, at the moment, returns only results if both override and default values exists:
    SELECT t1.id
    t1.def_id,
    t1.ovr_id
    FROM values t2,
    parameter t1,
    values t0
    WHERE nvl(t2.value, t0.value) = 15 AND
    t1.ovr_id = t2.id(+) AND t2.discriminator = 'OVR' AND
    t1.def_id = t0.id AND t0.discriminator = 'DEF'
    Situation Wanted:
    SELECT t1.id
    t1.def_id,
    t1.ovr_id
    FROM parameter t1
    LEFT JOIN values t2 ON (t1.ovr_id = t2.id AND t2.discriminator = 'OVR')
    JOIN values t0 ON (t1.def_id = t0.id AND t0.discriminator = 'DEF')
    WHERE nvl(t2.value, t0.value) = 15
    Anyone know if there is some statement I am missing to allow an actual outer join on descriptors containing class indicators/discriminators? A possible rewrite?
    Thanks in advance,
    Rudy

    This is a bug in TopLink's outer join support for Oracle. Currently the outer join is put in the where clause, instead of the from clause, as we do on other platforms. You might be able to fix it by changing your OraclePlatform to return false for shouldPrintOuterJoinInWhereClause().
    Please log this bug on EclipseLink, or through Oracle technial support.
    There is a workaround using,
    descriptor.getInhertiancePolicy().setAlwaysUseOuterJoinForClassType(true);
    James : http://www.eclipselink.org

  • What is the best way of returning group-by sql results in Toplink?

    I have many-to-many relationship between Employee and Project; so,
    a Employee can have many Projects, and a Project can be owned by many Employees.
    I have three tables in the database:
    Employee(id int, name varchar(32)),
    Project(id int, name varchar(32)), and
    Employee_Project(employee_id int, project_id int), which is the join-table between Employee and Project.
    Now, I want to find out for each employee, how many projects does the employee has.
    The sql query that achieves what I want would look like this:
    select e.id, count(*) as numProjects
    from employee e, employee_project ep
    where e.id = ep.employee_id
    group by e.id
    Just for information, currently I am using a named ReadAllQuery and I write my own sql in
    the Workbench rather than using the ExpressionBuilder.
    Now, my two questions are :
    1. Since there is a "group by e.id" on the query, only e.id can appear in the select clause.
    This prevent me from returning the full Employee pojo using ReadAllQuery.
    I can change the query to a nested query like this
    select e.eid, e.name, emp.cnt as numProjects
    from employee e,
    (select e_inner.id, count(*) as cnt
    from employee e_inner, employee_project ep_inner
    where e_inner.id = ep_inner.employee_id
    group by e_inner.id) emp
    where e.id = emp.id
    but, I don't like the complication of having extra join because of the nested query. Is there a
    better way of doing something like this?
    2. The second question is what is the best way of returning the count(*) or the numProjects.
    What I did right now is that I have a ReadAllQuery that returns a List<Employee>; then for
    each returned Employee pojo, I call a method getNumProjects() to get the count(*) information.
    I had an extra column "numProjects" in the Employee table and in the Employee descriptor, and
    I set this attribute to be "ReadOnly" on the Workbench; (the value for this dummy "numProjects"
    column in the database is always 0). So far this works ok. However, since the numProjects is
    transient, I need to set the query to refreshIdentityMapResult() or otherwise the Employee object
    in the cache could contain stale numProjects information. What I worry is that refreshIdentityMapResult()
    will cause the query to always hit the database and beat the purpose of having a cache. Also, if
    there are multiple concurrent queries to the database, I worry that there will be a race condition
    of updating this transient "numProjects" attribute. What are the better way of returning this kind
    of transient information such as count(*)? Can I have the query to return something like a tuple
    containing the Employee pojo and an int for the count(*), rather than just a Employee pojo with the
    transient int inside the pojo? Please advise.
    I greatly appreciate any help.
    Thanks,
    Frans

    No I don't want to modify the set of attributes after TopLink returns it to me. But I don't
    quite understand why this matters?
    I understand that I can use ReportQuery to return all the Employee's attributes plus the int count(*)
    and then I can iterate through the list of ReportQueryResult to construct the Employee pojo myself.
    I was hesitant of doing this because I think there will be a performance cost of not being able to
    use lazy fetching. For example, in the case of large result sets and the client only needs a few of them,
    if we use the above aproach, we need to iterate through all of them and wastefully create all the Employee
    pojos. On the other hand, if we let Toplink directly return a list of Employee pojo, then we can tell
    Toplink to use ScrollableCursor and to fetch only the first several rows. Please advise.
    Thanks.

Maybe you are looking for

  • LR4 error when reading from its preview cache, needs to quit

    I'm getting the above message.  Lightroom says it will attempt to fix this problem the next time it launches, requiring me to click OK and the program closes.  When I relaunch it, I see the same message. I'm on a PC w/ Win7; I updated LR4 with the 4.

  • Is there any function to automatically adjust the voice volume in the multitrack

    I'm trying to mix voice sounds and music files into one track. Sounds easy! But almost every music has its loud parts(for example the climax) and quiet parts. Therefore when i listen to the voice and the music at the same time, the voice files are so

  • TONS of broken software after downgrade from Lion...

    Ihave a 13" MBP with the 2.3GZz Intel COre i5 processor.  Itcame with Snow Leopard and in a moment of foolishness (Mac Newbie) Ispent the $29 and updated to Lion as soon as it came out.  Needlessto say, I was very unimpressed as I lost Front Page, Ex

  • PCMCIA ethernet card (wired) that will work with 10.4 tiger?

    i have unfortunately fried my ethernet port on my 1.33 al powerbook (applecare expired). I must use an ethernet PC adapter card that will work with Tiger 10.4. The Dlink adapter although mention OSX support only works until 10.3.9. Anyone here got su

  • Master Detail Form is ignoring the 4th join condition

    Hello All, I have master detail relationship between two tables with a composite foreign key (of 4 columns). I'm creating a master detail form in O9iAS Portal 3.0.9.8.0 on these 2 tables successfully with no errors. The only thing I have noticed, is