JPA and LEFT JOIN

I have a very basic question related to JPA.
I am using dict tables and connecting it to MaxDB.
In my Entity I have a select statement like this,
@NamedQuery  (name = "getOperations", query = "SELECT operT.id FROM SII_ARC_Oper operT " +
               "LEFT JOIN SII_ARC_Service serviceT " +
               "ON   operT.sid = serviceT.sid AND " +
               "serviceT.duuid =:duuid")
When I call this in my Bean, I get this error,
An error occurred processing the named query >>getOperations<< with the query string >>SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN SII_ARC_Service serviceT ON   operT.sid = serviceT.sid AND serviceT.duuid =:duuid<<. The exception text is: line 1: Variable 'SII_ARC_Service' not declared
SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN SII_ARC_Service serviceT ON   operT.sid = serviceT.sid AND serviceT.duuid =:duuid
                                                  ^
line 1: unexpected token: serviceT
SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN SII_ARC_Service serviceT ON   operT.sid = serviceT.sid AND serviceT.duuid =:duuid
I am just wondering how do I declare the u201CSII_ARC_Serviceu201D in my Entity before the Named Query. Or am I not declaring anything else..?
Thanks
Domnic
Edited by: domnic savio on Jul 21, 2008 12:16 PM

I have some improvements now although the problem is not solved yet,
I have the JPQL as
// The Named Query
@NamedQuery  (name = "getOperations", query = "SELECT oper.id FROM SII_ARC_Oper oper " +
               "LEFT JOIN oper.service serviceT " +
               "WHERE serviceT.duuid =:duuid")
// The many to one relationship
@Column(name= "SERVICE_TABLE")
     @ManyToOne(targetEntity=com.sap.sii.archeiver.SII_ARC_Service.class)
     @JoinColumn(referencedColumnName = "SID")
     private SII_ARC_Service service;
On calling the NamedQuery and passing a parameter, I get the error,
Errors have occurred during the precompilation of named queries:
An error occurred processing the named query >>getOperations<< with the query string >>SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN operT.service serviceT WHERE serviceT.duuid =:duuid<<. The exception text is: line 1: Path 'opert.service' is not association path.
SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN operT.service serviceT WHERE serviceT.duuid =:duuid
1) What association path does the compiler refer too !?!.
2) Is the JPQL Querry valid without an ON clause ?!.
anyone has an idea..!?!
thanks in advance
Domnic

Similar Messages

  • How to make a customize form with optional parameter and left join

    Hi,
    I am trying to make a report with a left join. I also want ot have optional parameters in it.
    I am using the Create Reports From SQL Query method:
    SQL is :
    select ename, sal
    from scott.emp left join scott.dept
    on scott.emp.deptno = scott.dept.deptno
    where sal >= :lower_sal
    and sal <= :higher_sal;
    However, if I do it this way, I those 2 parameters are not optional.... How can I make them optional?
    If I use the Create Reports From Query Wizard method, I can make the parameters optional, but then I cannot do the left join...
    Thanks,
    Wilson

    hi,
    to catch null values on both sides I use:
    where nvl(sal,0) >= nvl(:lower_sal,nvl(sal,0))
    and nvl(sal,0) <= nvl(:higher_sal,9999999999)
    otherwise there will be no rows in the report where the value of sal is null, even if there are no selection criteria entered.
    regards Michael

  • JPA Criteria : LEFT JOIN with an AND condition

    Hi all,
    I have a question regarding JPA criteria.
    Here is my JPA query :
    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
    Root<Email> emailRoot = criteriaQuery.from(Email.class);
    criteriaQuery.distinct(true);
    Predicate globalCondition = criteriaBuilder.equal(emailRoot.get(Email_.type), EmailType.in);
    Predicate responseMandatoryCondition = criteriaBuilder.equal(emailRoot.get(Email_.responseMandatory), true);
    Predicate typeCondition = criteriaBuilder.notEqual(emailRoot.join(Email_.emailsOut, JoinType.LEFT).get(Email_.responseType),ResponseType.response);
    globalCondition = criteriaBuilder.and(globalCondition, responseMandatoryCondition);
    globalCondition = criteriaBuilder.and(globalCondition, typeCondition);
    em.createQuery(mainCriteria.where(globalCondition)).getSingleResult();
    Here is the result of this query :
    SELECT DISTINCT email0_.ID AS col_0_0_
    FROM EMAIL email0_
    LEFT OUTER JOIN email emailso1_ ON email0_.ID = emailso1_.ID_EMAIL_IN
    WHERE email0_.TYPE = 'in'
    AND email0_.RESPONSE_MANDATORY = true
    AND emailso1_.RESPONSE_TYPE <> 'response'
    LIMIT 0 , 30
    And here is the request I needed :
    SELECT DISTINCT email0_.ID AS col_0_0_
    FROM EMAIL email0_
    LEFT OUTER JOIN email emailso1_ ON email0_.ID = emailso1_.ID_EMAIL_IN AND emailso1_.RESPONSE_TYPE <> 'response'
    WHERE email0_.TYPE = 'in'
    AND email0_.RESPONSE_MANDATORY = true
    LIMIT 0 , 30
    As you can see I need to check if the RESPONSE_TYPE is equals on the same line that the LEFT OUTER JOIN. Does anybody know how to write such an JPA criteria query ?
    Thanks ,
    Louis
    Edited by: user13105928 on 17 févr. 2011 03:06

    You cannot define an ON clause with Criteria, nor JPQL.
    Perhaps you can reword the query to avoid needing an ON clause.
    What is the query you want to do (in english)?
    Can you just use an OR in the where clause?
    There is a enhancement request to have ON clause support added, please vote for it.
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=312146
    James : http://www.eclipselink.org

  • JPA OnetoMany  QUERY LEFT JOIN BUG

    Using JPA in JDev 10.1.3.1.0.3984
    Database: Firebird 1.51LI-V1.5.3.4870 Firebird 1.5/tcp
    Driver: Jaybird JCA/JDBC driver Version: 2.1
    TopLink, version: Oracle TopLink Essentials - 2006.8 (Build 060829)
    If I use normal JOIN it works.
    On LEFT JOIN I get a {oj [/b] before the table name and a [b]} at the end.
    public class Cliente{
        @OneToMany(mappedBy = "cliente")
        @JoinColumn(name = "CDCLIENTE", referencedColumnName = "CDCLIENTEREQUISITANTE")
        private List<Requisicao> requisicoes;
    public class Requisicao
        @ManyToOne
        @JoinColumn(name = "CDCLIENTEREQUISITANTE", referencedColumnName = "CDCLIENTE")
        private Cliente cliente;
    EntityManager em = getEntityManager();
    String sql = "SELECT c FROM Cliente c LEFT JOIN c.requisicoes req";
    Query q = em.createQuery(sql);
    List rs = q.getResultList();Result SQL:
    SELECT DISTINCT t0. <OMITTED> FROM {oj [/b]CLIENTE t0 LEFT OUTER JOIN REQUISICAO t1 ON (t1.CDCLIENTEREQUISITANTE = t0.CDCLIENTE)[b]}

    You cannot define an ON clause with Criteria, nor JPQL.
    Perhaps you can reword the query to avoid needing an ON clause.
    What is the query you want to do (in english)?
    Can you just use an OR in the where clause?
    There is a enhancement request to have ON clause support added, please vote for it.
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=312146
    James : http://www.eclipselink.org

  • Problem with XMLTABLE and LEFT OUTER JOIN

    Hi all.
    I have one problem with XMLTABLE and LEFT OUTER JOIN, in 11g it returns correct result but in 10g it doesn't, it is trated as INNER JOIN.
    SELECT * FROM v$version;
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE     11.2.0.1.0     Production"
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    --test for 11g
    CREATE TABLE XML_TEST(
         ID NUMBER(2,0),
         XML XMLTYPE
    INSERT INTO XML_TEST
    VALUES
         1,
         XMLTYPE
              <msg>
                   <data>
                        <fields>
                             <id>g1</id>
                             <dat>data1</dat>
                        </fields>
                   </data>
              </msg>
    INSERT INTO XML_TEST
    VALUES
         2,
         XMLTYPE
              <msg>
                   <data>
                        <fields>
                             <id>g2</id>
                             <dat>data2</dat>
                        </fields>
                   </data>
              </msg>
    INSERT INTO XML_TEST
    VALUES
         3,
         XMLTYPE
              <msg>
                   <data>
                        <fields>
                             <id>g3</id>
                             <dat>data3</dat>
                        </fields>
                        <fields>
                             <id>g4</id>
                             <dat>data4</dat>
                        </fields>
                        <fields>
                             <dat>data5</dat>
                        </fields>
                   </data>
              </msg>
    SELECT
         t.id,
         x.dat,
         y.seqno,
         y.id_real
    FROM
         xml_test t,
         XMLTABLE
              '/msg/data/fields'
              passing t.xml
              columns
                   dat VARCHAR2(10) path 'dat',
                   id XMLTYPE path 'id'
         )x LEFT OUTER JOIN
         XMLTABLE
              'id'
              passing x.id
              columns
                   seqno FOR ORDINALITY,
                   id_real VARCHAR2(30) PATH '.'
         )y ON 1=1
    ID     DAT     SEQNO     ID_REAL
    1     data1     1     g1
    2     data2     1     g2
    3     data3     1     g3
    3     data4     1     g4
    3     data5          Here's everything fine, now the problem:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE     10.2.0.1.0     Production"
    TNS for HPUX: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    --exactly the same environment as 11g (tables and rows)
    SELECT
         t.id,
         x.dat,
         y.seqno,
         y.id_real
    FROM
         xml_test t,
         XMLTABLE
              '/msg/data/fields'
              passing t.xml
              columns
                   dat VARCHAR2(10) path 'dat',
                   id XMLTYPE path 'id'
         )x LEFT OUTER JOIN
         XMLTABLE
              'id'
              passing x.id
              columns
                   seqno FOR ORDINALITY,
                   id_real VARCHAR2(30) PATH '.'
         )y ON 1=1
    ID     DAT     SEQNO     ID_REAL
    1     data1     1     g1
    2     data2     1     g2
    3     data3     1     g3
    3     data4     1     g4As you can see in 10g I don't have the last row, it seems that Oracle 10g doesn't recognize the LEFT OUTER JOIN.
    Is this a bug?, Metalink says that sometimes we can have an ORA-0600 but in this case there is no error returned, just incorrect results.
    Please help.
    Regards.

    Hi A_Non.
    Thanks a lot, I tried with this:
    SELECT
         t.id,
         x.dat,
         y.seqno,
         y.id_real
    FROM
         xml_test t,
         XMLTABLE
              '/msg/data/fields'
              passing t.xml
              columns
                   dat VARCHAR2(10) path 'dat',
                   id XMLTYPE path 'id'
         )x,
         XMLTABLE
              'id'
              passing x.id
              columns
                   seqno FOR ORDINALITY,
                   id_real VARCHAR2(30) PATH '.'
         )(+) y ;And is giving me the complete output.
    Thanks again.
    Regards.

  • Difference between merge-Not matched and left outer join

    Why should Merge-Not Matched be used instead of left outer join? I believe both will enable comparison of 2 tables. So what is the difference. Please advice.
    mayooran99

    MERGE is way to encapsulate all conditions within single statement
    The equivalent implementation using join would require three different statements 
    1 UPDATE using INNER JOIN
    1 INSERT using LEFT JOIN
    and 1 DELETE using LEFT JOIN in reverse order
    Both approaches work fine
    so all that you need to do is left join operation to find difference you can use either
    But MERGE has one additional advantage in case you need to get output from MERGE and use it for further manipulation like further insert to child table
    I've explained it here
    http://visakhm.blogspot.in/2014/09/t-sql-tips-multifaceted-merge-statement.html
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Differences between left join in oracle8 style and oracle10g style

    Hi,
    I need some help to figure out what impact can be, on a product, the migration of query left join syntax from the Oracle8 one to the Oracle10g:
    we have a product that uses Hibernate configured to use the Oracle8 dialect to perform queries which uses the (+) sintax to perform outer join query, and we encountered a bug in that dialect that is forcing us to move on the Oracle10g dialect which uses the ANSI 92 style to perform outer join queries.
    Someone know if there are differences/bugs/incompatibilities for outer join query written using the ANSI 92 style instead the Oracle8 style like DB functions (like NVL(), DECODE(), and so on) that work in a different way using a style instead the other?
    Thanks.
    Luca.

    luca.depetrillo wrote:
    Hi,
    I need some help to figure out what impact can be, on a product, the migration of query left join syntax from the Oracle8 one to the Oracle10g:
    we have a product that uses Hibernate configured to use the Oracle8 dialect to perform queries which uses the (+) sintax to perform outer join query, and we encountered a bug in that dialect that is forcing us to move on the Oracle10g dialect which uses the ANSI 92 style to perform outer join queries.
    Someone know if there are differences/bugs/incompatibilities for outer join query written using the ANSI 92 style instead the Oracle8 style like DB functions (like NVL(), DECODE(), and so on) that work in a different way using a style instead the other?
    Thanks.
    Luca.In earlier versions of 10g (i.e. 10.1.?.?) there was a few bugs in the ANSI syntax joins on SQL, but they seemed to have sorted most of those out for 10.2.?.? onwards.
    Essentially there will be no real adverse effects in using ANSI syntax, and it shouldn't stop your other functions working.
    ANSI syntax also gives you the advantage that you can outer join to more than one table which you can't do in Oracle syntax outer joins.
    Edited by: BluShadow on Nov 18, 2008 2:06 PM
    prevented stupid forum formatting

  • Left join and where clause with not equal ( ) returns too many rows

    Say I have something like this
    Table A
    =========
    Id
    OrderNum
    Date
    StoreName
    AddressKey
    Table B
    ========
    Id
    StreetNumber
    City
    State
    select a.* from [Table A] a
    left join [Table B] b on a.AddressKey = b.Id
    where a.StoreName <> 'Burger place'
    The trouble is that the above query still returns rows that have StoreName = 'Burger place'
    One way Ive handled this is to use a table expression, select everything into that, then select from the CTE and apply the filter there.  How could you handle it in the same query however?

    Hi Joe,
    Thanks for your notes.
    INT SURROGATE PRIMARY KEY provides a small footprint JOIN ON column. Hence performance gain and simple JOIN programming.  In the Addresses table, address_id is 4 bytes as opposed to 15 bytes san. Similarly for the Orders table.
    INT SURROGATE PRIMARY KEY is a meaningless number which can be duplicated at will in other tables as FOREIGN KEY.  Having a meaningful PRIMARY KEY violates the RDBMS basics about avoiding data duplication.  If I make CelebrityName (Frank Sinatra)
    a PRIMARY KEY, I have to duplicate "Frank Sinatra" as an FK wherever it needed as opposed to duplicating SURROGATE PRIMARY KEY CelebrityID (79) a meaningless number.
    This is how we design in SQL Server world.
    QUOTE from Wiki: "
    Advantages[edit]
    Immutability[edit]
    Surrogate keys do not change while the row exists. This has the following advantages:
    Applications cannot lose their reference to a row in the database (since the identifier never changes).
    The primary or natural key data can always be modified, even with databases that do not support cascading updates across related
    foreign keys.
    Requirement changes[edit]
    Attributes that uniquely identify an entity might change, which might invalidate the suitability of natural keys. Consider the following example:
    An employee's network user name is chosen as a natural key. Upon merging with another company, new employees must be inserted. Some of the new network user names create conflicts because their user names were generated independently (when the companies
    were separate).
    In these cases, generally a new attribute must be added to the natural key (for example, an
    original_company column). With a surrogate key, only the table that defines the surrogate key must be changed. With natural keys, all tables (and possibly other, related software) that use the natural key will have to change.
    Some problem domains do not clearly identify a suitable natural key. Surrogate key avoids choosing a natural key that might be incorrect.
    Performance[edit]
    Surrogate keys tend to be a compact data type, such as a four-byte integer. This allows the database to query the single key column faster than it could multiple columns. Furthermore a non-redundant distribution of keys causes the resulting
    b-tree index to be completely balanced. Surrogate keys are also less expensive to join (fewer columns to compare) than
    compound keys.
    Compatibility[edit]
    While using several database application development systems, drivers, and
    object-relational mapping systems, such as
    Ruby on Rails or
    Hibernate, it is much easier to use an integer or GUID surrogate keys for every table instead of natural keys in order to support database-system-agnostic operations and object-to-row mapping.
    Uniformity[edit]
    When every table has a uniform surrogate key, some tasks can be easily automated by writing the code in a table-independent way.
    Validation[edit]
    It is possible to design key-values that follow a well-known pattern or structure which can be automatically verified. For instance, the keys that are intended to be used in some column of some table might be designed to "look differently from"
    those that are intended to be used in another column or table, thereby simplifying the detection of application errors in which the keys have been misplaced. However, this characteristic of the surrogate keys should never be used to drive any of the logic
    of the applications themselves, as this would violate the principles of
    Database normalization"
    LINK: http://en.wikipedia.org/wiki/Surrogate_key
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Why Left and Right Joins if only one of them can serve the same purpose?

    I understand that left join is used to display all the records from left table whereas the right join is used to display all the records from right table in a join.
    However, if we switch the positions of the join tables and perform left join we can get all the records of the left table.
    A left join B -> will give all records from A
    A right join B ->will give all records from B
    B left join A -> will again give all records from B.
    The order in which the data is displayed(ie the field order) can also be maintained in the SELECT clause.
    So, Why do we have left and right joins separately in existance, when only one of them can serve the same purpose?

    Hi,
    I think it's because it is sometime more natural to outer join on left or right.
    In your data model (or the query you are writing), there is some kind of hierarchy between tables : I feel more natural to have the table with lowest hierarchical level (the root table) on the left. So I sometimes prefer to right outer join...
    This is a very personal feeling, I must admit.
    To me what is strange is to have chosen left and right as they refer to a "latin" reading direction => forward join and backward join would be more meaningful for people that read from right to left.
    +And I prefer the new joining syntax that doesn't us the {noformat}(+){noformat} sign...+

  • Select from 2 tables with common key and than left join(unique result)

    Hi,
    I have 2 tables that have a common id (Customer_id) and I have a third table which contain her key consist of 3 column ( Customer_id , rms_customer_id,billind_tree_id) and have the manager_name field
    I am using a left join because not all the customers have a manager.
    I need to take only the manager_name field from the left join but the problem is that I am not getting a unique name results because the customer_id is not the primary key(only part of )
    so I have use the following :
    left join
    ( select * from ACCOUNT_Manager am where
    rms_customer_id <= all (select rms_customer_id from ACCOUNT_Manager am2 where
    am2.customer_id = am.customer_id )) am
    on c.ID = am.CUSTOMER_ID (C is one of the first 2 tables with the ID as key)
    Is there anyway more efficient of doing it ?
    Thanks

    Please consider the following when you post a question. This would help us help you better
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • JPQL LEFT JOIN FETCH Results in NPE when DescriptorCustomizer in Place

    I have a unidirectional one-to-many mapping between the following two entities:
    @Entity
    @Table(name="INVC_CNTRL")
    public class InvoiceControl implements Serializable {
        @Id
        @Column(name="INVC_CNTRL_ID")
        private Long invoiceControlId = null;
        @OneToMany(fetch = FetchType.LAZY)
        private List userDefineds;
    @Entity
    @Table(name="USER_DEFINED")
    public class UserDefined implements Serializable {
        @Column(name="USER_DEFINED_TABLE")
        private java.lang.String userDefinedTable;
        @Column(name="USER_DEFINED_FK")
        private long userDefinedForeignKey;
    I wrote the following DescriptorCustomizer to address a constant JoinColumn value:
            ManyToManyMapping mapping = (ManyToManyMapping) descriptor.getMappingForAttributeName("userDefineds");
            if (null != mapping) {
                String tableName = descriptor.getTableName();
                String primaryKey = descriptor.getPrimaryKeyFields().get(0).getName();
                ExpressionBuilder builder = new ExpressionBuilder(mapping.getReferenceClass());
                mapping.setSelectionCriteria(builder.getField("USER_DEFINED_FK").equal(builder.getParameter(primaryKey))
                    .and(builder.getField("USER_DEFINED_TABLE").equal(tableName)));
    This works as expected with JPQL "select a from InvoiceControl a join fetch a.userDefineds" but when I change the "join fetch" to "left join fetch", I get the following NPE:
    Caused by: java.lang.NullPointerException
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.appendFromClauseForOuterJoin(SQLSelectStatement.java:403)
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.appendFromClauseToWriter(SQLSelectStatement.java:521)
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.printSQL(SQLSelectStatement.java:1679)
         at org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printSQLSelectStatement(DatabasePlatform.java:3178)
         at org.eclipse.persistence.platform.database.OraclePlatform.printSQLSelectStatement(OraclePlatform.java:932)
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:782)
         at org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:792)
         at org.eclipse.persistence.descriptors.ClassDescriptor.buildCallFromStatement(ClassDescriptor.java:813)
         at org.eclipse.persistence.internal.queries.StatementQueryMechanism.setCallFromStatement(StatementQueryMechanism.java:390)
         at org.eclipse.persistence.internal.queries.StatementQueryMechanism.prepareSelectAllRows(StatementQueryMechanism.java:315)
         at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1721)
         at org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:813)
         at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:744)
         at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:661)
         ... 8 more
    Inspecting the 2.5.1 source, this suggests relationAlias is null.
    I've tried a number of things to no avail. If I disable the DescriptorCustomizor and instead add a @JoinColumn on the OneToMany defining half of the join, it works. Of course the result is incorrect because it's failing to discriminate by the table name.
    Is this a bug or am I making another JPA noob mistake?
    Thanks.

    I was able to get similar behaviour doing similar JPQL. I have entered a bug in TopLink Essentials. 2465.
    I did note that having the objects in memory made a significant difference (< .5 seconds for 1000 objects, each with 2 in the 1:M).

  • Left joins : Case or if statement

    Hi
    I want to know if one can build in a case or if statement into a left join. I want to multiply a value with -1 if the condition is met.

    I think it is not possible in SELECT statement...but you can do the below to resolve it.
    add a field for FKART in your internal table.
    TYPES: BEGIN OF tab ,
           kunag LIKE vbrk-kunag,
           fkdat like vbrk-fkdat,
           matnr LIKE vbrp-matnr,
           werks LIKE vbrp-werks,
           fkart like vbrk-fkart,
           volum LIKE vbrp-volum,
           END OF tab.
    DATA: wa_outtab TYPE table of tab WITH HEADER LINE.
    SELECT akunag  afkdat
           bmatnr bwerks a~fkart
           SUM( b~volum )
       INTO  table wa_outtab
    FROM vbrk AS a
    INNER JOIN vbrp AS b
          ON  avbeln  = bvbeln
    WHERE
    avbeln = bvbeln                                                                               
    AND ( afkart LIKE 'F2' OR afkart LIKE 'RE' )
    GROUP BY  akunag afkdat bmatnr bwerks a~fkart.
    sort wa_outtab.
    Loop at wa_outtab.
      if wa_outtab-fkart = 'RE'.
        lpos = lpos +  wa_outtab-volum.
      else.
        lneg = lneg +  wa_outtab-volum.
      endif.
      at end of werks.
         lvaule = lpos - lneg.
        lpos = lneg = 0.
      endat.
    endloop.

  • Left Join query: revisited... I have to explain at user meeting tomm. pls..

    Hi Everyone,
    Can someone pls shed some light on the situation below
    I am understanding alot of what Michael and Rod wrote.... with my prev. post of LEFT JOIN and testing for
    not null and doing a double Boolean OR etc.
    - but- AM NOT understanding why the IS NOT NULL works, without the double boolean OR
    Pls help... have to explain what left join means to user tomm. I'm going to demo the query below and
    not the one with the double boolean OR bec. maybe too much info to present at one sitting. tx, sandra
    =====================
    the query below is left joining the STUDENT table to
    HOLD table.
    The HOLD table - contains rows for students who have holds on their record.
    a student can have more than one hold (health, HIPAA, basic life saving course)
    BUT, for this query: I'm only interested that a hold exists, so I'm choosing MAX on hold desc.
    Selecting a MAX, helps me, bec. it reduces my join to a 1 to 1 relationship, instead of
    1 to many relationship.
    Before I posted this thread at all, the LEFT JOIN below testing for IS NOT NULL worked w/o
    me having to code IS NOT NULL twice....
    Is that because, what's happening "behind the scenes" is that a temporary table containing all max rows is being
    created, for which Discoverer has no predefined join instructions, so it's letting me do a LEFT JOIN and have
    the IS NOT NULL condition.
    I would so appreciate clarification. I have a meeting on Tues, for which I have to explain LEFT JOINS to the user
    and how they should create a query. I need to come up with rules.
    If I feel "clear", I asked my boss to buy Camtasia videocast software to create a training clip for user to follow.
    Also, if any Banner user would like me to email the DIS query to run on their machine, I would be glad to do so.
    thx sooo much, Sandra
    SELECT O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID, MAX(O100255.HOLD_DESC)
    FROM ODSMGR.HOLD O100255, ODSMGR.STUDENT O100384
    WHERE ( ( O100384.PERSON_UID = O100255.PERSON_UID(+) ) ) AND ( O100384.ACADEMIC_PERIOD = '200820' )
    GROUP BY O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID
    HAVING ( ( MAX(O100255.HOLD_DESC(+)) ) IS NOT NULL )
    ORDER BY O100384.NAME ASC

    Hi,
    OK, I will try to explain this. When you outer join table B to table A then the rows in table A which do not match any rows in table B will returned with NULL in the columns from the table B.
    Oracle uses the syntax ( +) for outer joins. Now if you add another condition using the ( +) syntax (as shown below) the condition will be processed before the table is joined. Therefore if table A does not match any rows in table B which have col2=1 then the row from table A will be returned with NULLs for the table B columns.
    SELECT A.col1, B.col1
    FROM A, B
    WHERE A.col1 = B.col1( +)
    AND B.col2( +)=1
    Now, if the condition B.col2=1 was used instead then the condition would be processed after the join and therefore the rows from table A that were joined to table B but did not meet the condition would not be returned by the query.
    This applies to a WHERE clause and to the HAVING clause, but with one exception. If you use the ( +) within a group function in a HAVING clause then the ( +) will have no affect because the condition must be processed after group by and group by can only be processed after the join. Therefore MAX(B.col2( +)) = 1 is processed after the join even through it uses the ( +) syntax.
    You cannot use an OR or an IN with the ( +) syntax because the meaning of the OR in this situation is ambiguous, is the OR done before or after the join. A query with an OR or IN in an outer will fail with an Oracle ORA-01719 error. Discoverer recognises this situation and removes the ( +) so that the error does not occur. However, without the ( +) the conditions are processed after the join.
    Using the ( +) with IS NULL, e.g. col2( +) IS NOT NULL works in the same way. You just have to remember that the col2( +) could be NULL as a result of the outer join and therefore if the condition is processed after the query then the IS NOT NULL will remove the outer joined rows.
    Hope that is clear.
    Rod West

  • Left joins on multi-million rows

    i have a simple query doing left joining on several tables, upward of 7 tables. each table has several hundred million rows.
    tblA is 1:M tblB and tblB is 1:M tblC and so on.
    how to tune a query liked that?
    sample query is
    select distinct
    a.col,b.col,c.col
    from tblA a left join tblB b
    on a.id=b.id
    and a.col is not null
    left join tblC
    on b.id=c.id
    and c.col > criteria
    thanks.

    hi
    a simple query is liked
    SELECT my_DEP.description,
    my_DEP.addr_id,
    hundredRowsTbl.address,
    5MillTbl.checkin_TIME,
    5MillTbl.checkout_TIME,
    hundredRowsTbl.ID2,
    5MillTbl.ID,
    5MillTbl.col2,
    my_DEP.col3,
    5MillTbl.col13,
    hundreds.desc,
    50mmTbl.col6,
    50mmTbl.col5,
    5MillTbl.col33
    FROM
    my.5MillTbl 5MillTbl
    LEFT OUTER JOIN
    my.50mmTbl 50mmTbl
    ON 5MillTbl.ID = 50mmTbl.ID
    LEFT OUTER JOIN my.hundreds hundreds
    ON 5MillTbl.banding =
    hundreds.banding
    INNER JOIN my.my_DEP my_DEP
    ON 5MillTbl.organization_ID = my_DEP.organization_ID
    INNER JOIN my.my_40millTbl
    ON 5MillTbl.seqID = my_40millTbl.seqID
    LEFT OUTER JOIN my.hundredRowsTbl hundredRowsTbl
    ON my_DEP.addr_id = hundredRowsTbl.ID2
    LEFT OUTER JOIN my.30millTbl 30millTbl
    ON my_DEP.organization_ID = 30millTbl.dept_id
    WHERE 1=1
    AND 5MillTbl.ID IS NOT NULL
    AND ( 5MillTbl.checkout_TIME >= TO_DATE ('01-01-2009 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
    AND 5MillTbl.checkout_TIME <TO_DATE ('12-31-2010 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
    AND ( 5MillTbl.col2 IS NULL
    OR NOT (5MillTbl.col2 = 5
    OR 5MillTbl.col2 = 6)
    AND 5MillTbl.ID IS NOT NULL
    AND 30millTbl.TYPE= '30'
    AND my_DEP.addr_id = 61

  • Left join (+) instead of "not in"

    Hi all!
    I've got statement with "where dig not in (840, 978)" string.
    How do I write statement without "not in" ?
    I thought about left join and "is not null", but don't know exactly how to use it.
    Any ideas?
    Thanks ahead.

    Here is my solution:
    select d.* from
    (select 111 as accountno, 840 as currencyid from dual
    union all
    select 222 as accountno, 978 as currencyid from dual
    union all
    select 333 as accountno, 826 as currencyid from dual ) d ,
    (select 840 as dig from dual
    union all
    select 978 as dig from dual ) j
    where d.currencyid = j.dig(+)
    and j.dig is null
    Thanks to all.

Maybe you are looking for

  • Having trouble connecting from office to home

    So I downloaded ARD last night finally to address the daily questions from the kids and wife (how do I do this, Can you install this program, etc.) Played around with it a bit last night at the house (FIOS Router to Time Machine Bridge Mode) and loca

  • How to create new user account and delete old one?

    Greetings, we have wanted to change our alias on the discussions group but understand from the frequently asked questions section that, "Once you create an alias, you cannot make changes to it. If you want to change your alias, you will need to creat

  • IBooks Author / iTunes Producer Import Error

    Looking for some help.... I have now attempted 9 different imports of my iBook Textbook created with iBooks Author - all ended in Import Error.   I have scoured the forums and took some community members'  advice to: Change all my video formats to iP

  • HT1386 iPhone 5 (iOS 7.1) cannot sync with itunes 11.1.5.

    Both my iPhone and iTunes are updated, iOS 7.1 and iTunes 11.1.5. However, not only can they not wifi sync, when I plug in my iPhone, my iTunes doesn't respond. The iPhone tab did not pop up. When I go under "File" -> "Devices", nothing is there when

  • By Pass Admin Rights when installing Flash Player 9

    We currently incoporate Flash Player 9 with our proprietary application so our clients users may utilize it efficiently. The issue is now we are in the process of rolling the application to user's across the country and a good percentage of the do no