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

Similar Messages

  • Oracle 8i, left join with conditional

    Coming from the MySQL world, I'm trying to do a left join with a
    condition:
    select c.givenname,c.surname,c.userid,r.letternr
    from cand c,responses r
    where (c.userid=r.username(+))
    and
    c.activeprofile=1
    No problem whatsoever.
    If there is no corresponding "response" in R for a given
    candidate, I get a NULL return for R.letternr.
    However, there is a flag in R, called "VISIBLE" that I wish to
    use to mean "Don't count this entry in R". R.VISIBLE=0 means
    that the response is not active/present/visible/valid.
    Am I making any sense? :-)

    If you don't want to display a row with a null value for
    r.letternr when r.visible = 0, then:
    SELECT     c.givenname,
               c.surname,
               c.userid,
               r.letternr
    FROM       cand c,
               responses r
    WHERE      c.userid = r.username (+)
    AND        c.activeprofile = 1
    AND        r.visible != 0
    Or, if you do want to display a row with a null value for
    r.letternr when r.visible = 0, then:
    SELECT     c.givenname,
               c.surname,
               c.userid,
               r.letternr
    FROM       cand c,
               responses r
    WHERE      c.userid = r.username (+)
    AND        c.activeprofile = 1
    AND        r.visible (+) != 0

  • My Ipad has a white square with Terms and conditions, on the bottom is agree one the right, disagree on the left, but no button works? All this happend after I started an update from Chrome?

    Terms and
    Conditions
    Send by Email
    IMPORTANT c.etc.etc.etc. etc etc
    A. iCloud terms                          >
    B. Privacy Policy                      >
    ;kgj;kvjkbkjb/jb/ljb/jb/skdjvb kjsbkjb
    sjk/vb.skjbv.kjbv.kjbvkjbv.kfjdbv.kjbv
    .samndb .as b.s, , ß≤ kh.sdv;iyegveiu
    etc.etc.
    Disagree                                                                            Agree

    Reset iPad and continue with update.
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • Data Foundation table joins with filters (multi-conditional joins)

    My environment: Crystal Server 2011, Business View Manager 14.0.2.364, Crystal Reports 2011 with SP2 and FP28
    In our existing database we make use of a single lookup table for many different types of selection lists.
    For example, the lookup table might have selections for all of the US States (ex: NonUniqueIDValue = 123,  Value1=TX, Value2=Texas, LookupType=US_STATES) and another list of selections for OrderStatus (ex: NonUniqueIDValue = 123,   Value1=OPEN, Value2=NULL, LookupType=ORDER_STATUS).
    It is necessary to supply addtional filtering on the join statement since the IDVaule for these entries are NOT unique.
    Using SQL written joins for the two examples above would look like this:
    join lookupTable on lookupTable.NonUniqueIDValue = mainTable.US_StateID AND lookupTable.LookupType = 'US_STATES'
    join lookupTable on lookupTable.NonUniqueIDValue = mainTable.OrderStatus AND lookupTable.LookupType = 'ORDER_STATUS'
    I am new to Business Views and don't readily see a solution since it appears the DF Linking window only suports single basic conditional testing (<, >, =, etc) . How can I accomplish this in my DF or elsewhere in the BV?
    I would greatly appreciate any feedback or insight anyone might have on how to accomplish these kinds of filtered joins.
    Thanks in advance...

    Hi Paul
    If the query returns 100,000,000 rows, there will be performance issues of the report based on the connection and the datasource you are using.
    If you use a Command Object or a Stored Procedure the query will be directly executed at the database level and the performance will not be affected much.
    Hope this helps!
    Thanks

  • LEFT JOINING with a string?

    I'm viewing code where the person left joined a column with a string.
       lu_ods.lookup_type(+) = 'FORX_ORDERPRO_ACTION'Is this just bad coding. Is there any reason why someone would do this?
    Doesn't
       lu_ods.lookup_type = 'FORX_ORDERPRO_ACTION'work just as well?

    As Sentinel said, it can change the result if you are left joining between two tables:
    with a as (
    select 1 num, 'a' col from dual UNION ALL
    select 2 num, 'b' col from dual UNION ALL
    select 3 num, 'c' col from dual
    b as (
    select 1 num, 'a' col from dual UNION ALL
    select 4 num, 'e' col from dual UNION ALL
    select 5 num, 'f' col from dual
    select *
    from a, b
    where a.num(+) = b.num
      and a.num(+) = 1;
    NUM                    COL NUM                    COL
    1                      a   1                      a  
                               5                      f  
                               4                      e  
    3 rows selectedWithout the left join on the number, we lose results:
    with a as (
    select 1 num, 'a' col from dual UNION ALL
    select 2 num, 'b' col from dual UNION ALL
    select 3 num, 'c' col from dual
    b as (
    select 1 num, 'a' col from dual UNION ALL
    select 4 num, 'e' col from dual UNION ALL
    select 5 num, 'f' col from dual
    select *
    from a, b
    where a.num(+) = b.num
      and a.num = 1;
    NUM                    COL NUM                    COL
    1                      a   1                      a  
    1 rows selected

  • Doughts on Infoset Joins with Cube and DSO in BI 7

    Dear All,
    I have a droughts on Infoset Joints.
    I am working on a BI Query where I need to take 0Employee from Cube and Employee position time he holds in an Organization is coming form DSO, Apart for this I also have other requirement such as Address fields , Visa Status , are all coming from DSO.
    I have created a Infoset for this where
    1st is Cube and its 0Employee is linked to all DSO Employee and also Employee position I have linked with DSO and all are inner joints.
    1>My doughty is that will this work with inner joins or I have to use other joints.
    2>Is sequence of Data Target is correct
    which is
    1> Cube and in 2> all DSO in Parallel.
    Please guide me on joints and sequence.
    Thanks V V much in Advance,
    Regards,

    Hi,
    Check these links.
    http://help.sap.com/saphelp_nw04s/helpdata/en/ed/084e3ce0f9fe3fe10000000a114084/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/2f5aa43f-0c01-0010-a990-9641d3d4eef7
    http://help.sap.com/saphelp_nw04/helpdata/en/9c/6b7538c9a8ee45e10000009b38f8cf/frameset.htm
    if this helpa assign points.
    Thanks.....
    Vasu.....

  • RH6 crashes with th and conditional build tags

    Hello together,
    The attached code worked fine with RH X5, but leads to a
    crash with X6. To fix, you have to replace the <th> by
    <td>, but it is not too easy to find the topic within a
    project. The fix is quite easy, but it is hard to find in a big
    project.
    This happens, when the conditional build tag is used.
    Thanks and best regards,
    Katrin Lusser

    Hello Peter,
    My wife created the topic with X3 or X5.
    She just tried again with X6 and after several changes (set
    heading, insert, delete, etc.) she had the same constellation.
    Unfortunately, until now, she could not find out the exact way to
    reproduce. But it is definitely possible. We will post here, when
    we find out, how to do it.
    Best regards,
    Michael

  • When i try to upgrade iPad, i cannot proceed with terms and conditions page

    i forgot my apple ID password when i after i upgrade my ipad. So i changed reset my password online. After i entered new password, terms and conditions page appeared, however there was no response no matter what option i choose be it agree, disagree or A and B.
    maybe i accidentally disconnected my ipad with my Mac air at that time? I was not paying attention to that. now i dont konw what i can do.
    i do not know the version of the previous system. however i updated as it pompted up that there is a new update.

    Reset iPad and continue with update.
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • CAML Query with 10 AND conditions

    Hello,
    I need some help with a CAML query. This particular query needs to have 10 AND conditions. Quite frankly, with all the nesting it is driving me a little nuts:
    What I have is:
    <Query>
    <Where>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <And>
    <Eq><FieldRef Name='Column1' LookupId='TRUE' /><Value Type='Text'>10341</Value></Eq>
    <Eq><FieldRef Name='Column2' LookupId='TRUE' /><Value Type='Text'>9539</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column3' LookupId='TRUE' /><Value Type='Text'>183</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column4' LookupId='TRUE' /><Value Type='Text'>35</Value></Eq>
    </And>
    <IsNull><FieldRef Name='Column5' /></IsNull>
    </And>
    <Eq><FieldRef Name='Column6' LookupId='TRUE' /><Value Type='Text'>4387</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column7' LookupId='TRUE' /><Value Type='Text'>4204</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column8' LookupId='TRUE' /><Value Type='Text'>36</Value></Eq>
    </And>
    <Eq><FieldRef Name='Column9' LookupId='TRUE' /><Value Type='Text'>213</Value></Eq>
    </And>
    <IsNull><FieldRef Name='Column10' /></IsNull>
    </And>
    </Where>
    </Query>
    I have added this into my ItemAdding Event Receiver as it will basically do a check for duplicate items based on the 10 columns. 
    If anyone can help guide me in this, it would be much appreciated. I have been using a CAML Query Builder to help.

    http://webcache.googleusercontent.com/search?q=cache:xji7jOxa5_EJ:aasai-sharepoint.blogspot.com/2013/02/caml-query-with-multiple-conditions.html+&cd=3&hl=en&ct=clnk&gl=in
    http://stackoverflow.com/questions/6203821/caml-query-with-nested-ands-and-ors-for-multiple-fields
    Since you are not allowed to put more than two conditions in one condition group (And | Or) you have to create an extra nested group (MSDN). The expression
    A AND B AND C looks like this:
    <And>
    A
    <And>
    B
    C
    </And>
    </And>
    Your SQL like sample translated to CAML (hopefully with matching XML tags ;) ):
    <Where>
    <And>
    <Or>
    <Eq>
    <FieldRef Name='FirstName' />
    <Value Type='Text'>John</Value>
    </Eq>
    <Or>
    <Eq>
    <FieldRef Name='LastName' />
    <Value Type='Text'>John</Value>
    </Eq>
    <Eq>
    <FieldRef Name='Profile' />
    <Value Type='Text'>John</Value>
    </Eq>
    </Or>
    </Or>
    <And>
    <Or>
    <Eq>
    <FieldRef Name='FirstName' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    <Or>
    <Eq>
    <FieldRef Name='LastName' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    <Eq>
    <FieldRef Name='Profile' />
    <Value Type='Text'>Doe</Value>
    </Eq>
    </Or>
    If this helped you resolve your issue, please mark it Answered

  • Sql query data horizontally with sum and condition in a row

    I am trying to get data from the following query in a row with total but not succeed and getting error message. Please help and advise.
    Select empid,name,country,
    sum(case category when 'JOB' then sum(core+RR) else 0 end) as 'JOB-Sum',
    sum(case category when 'PRIVATE' then sum(core+PP) else 0 end) as 'PRIVATE-Sum',
    group by empid,name,country
    Note: Following query is good for getting result in one row but i have to put sum calculation with 'THEN' and want result in a row.
    SELECT ID, MAX(case when Col1 = 'Yes' then 1 else 0 end) AS Col1,
    MAX(case when Col2 = 'Yes' then 1 else 0 end) AS Col2
    FROM MyTable
    GROUP BY ID

    Please show some sample data and expected output.
    Regards,
    Rob.

  • Whats the alternate for left join with using IN operator in the where claus

    My senario...
    Select t1.f1, t1.f2, t2.f3
      From t1, t2
    Where ...
          t1.f1> (+) IN t2.f1
          ...alternate query..
    Select t1.f1, t1.f2, t2.f3
      From t1, t2
    Where ...
          (t1.f1> IN t2.f1 or 1=1)
          ...will the alternate query satisfy the above senario..?

    I'm not quite sure I've understood what the OP's question is, but will ANSI syntax deal with it?
    SQL> ed
    Wrote file afiedt.buf
      1  with a as (select 1 as num, 2 as data from dual union all
      2             select 2 as num, 3 as data from dual union all
      3             select 3 as num, 4 as data from dual),
      4       b as (select 1 as num, 5 as data from dual union all
      5             select 3 as num, 7 as data from dual)
      6  -- END OF TEST DATA
      7  select a.num, a.data, b.data
      8* from a LEFT OUTER JOIN b ON (a.num = b.num AND b.num IN (3))
    SQL> /
           NUM       DATA       DATA
             3          4          7
             1          2
             2          3
    SQL>

  • PO Report with lines and conditions matched

    Dear Experts,
    I need a report that controls the Invoice Verification in the following scenario:
    1- The  PO's have product lines and have on conditions there is excise duty
    2 -  The invoice verification due to the type of business, it is manual and happens in two different moments;
    2.a - on the first moment "day X"  - it is made the invoice verification regarding the product
    2.b - on the second moment  ("day X" plus 15 days) it is done the invoice verification of the excice duty (it is invoiced on a separate invoice
    We need a report that gives the invoices where excise duty was not yet matched , or still open just for excise duty invoice verification.
    Many thanks in advance for your help
    Best Regards
    Jose

    Dear,
    Better send Requirements & specification form to ABAPer and discuss the possibilities, since 2.a and 2.b are looks not achievable with standard.
    Regards,
    Syed Hussian.

  • When I create a calendar, in iphoto 8, I had an information pane lower left corner with date and time of the picture. Can it possibly be that the iphoto developers forgot about that in iphoto 9? This was very helpful when placing images according to date.

    Today I updated to the latest iphoto version. The update itself went smooth and nice as one is used to from Apple. But when I wanted to finish my already started calendar, I have encountered two problems. The first is that I can't view the aperture library anymore directly from iphoto. Instead I have to open the iphtoto library in aperture but then my calendar isn't there. So now I have to copy images back and forth. No problem.
    However, the old iphoto had a small information area in the lower left corner which was very nice to place images on an exact date. This seems to be gone...?? Really? How am I supposed to sort images according to date and time when I have to back to the library view every time? That's not very convenient..Or am I missing something?
    Thanks for ANY help!
    Patrick

    The first is that I can't view the aperture library anymore directly from iphoto.
    THat is exceeding strange since iPhoto '08 could not open or share an Aperture library - that ability was first introduced in iPhoto '11 - with the latest version of iPhoto and or Aperture you can open the same library with either application - http://support.apple.com/kb/HT5043
    In the current version of iPhoto the photos are sorted by date in the film strip - I've not recently done a calendar so do not remember the specifics -
    LN

  • Problem in join with hrp1000 and hrp1001???

    Hi all, I am pasting code sAmpLE, i am having problem with join, without join the query is working. Help out.
    IF per_no IS NOT INITIAL.
        SELECT objid sobid objid INTO TABLE lt_st_p1
          FROM hrp1001 WHERE otype EQ 'P' AND objid IN per_no
          AND plvar EQ lv_plan_version AND rsign EQ 'B' AND relat EQ '008' AND istat EQ '1'
           AND subty EQ 'B008' AND sclas EQ 'S'.
       LOOP AT lt_st_p1 INTO ls_st_p1_tem.
         ls_st_p1_tem-sobid1 = ls_st_p1_tem-pernr.
         MODIFY lt_st_p1 FROM ls_st_p1_tem TRANSPORTING sobid1.
       ENDLOOP.
        check lt_st_p1 is not INITIAL.
        SELECT h1objid h1sobid h0~stext INTO TABLE lt_st_p1_temp
          FROM hrp1001 AS h1 JOIN hrp1000 as h0 on ( h1objid eq h0objid and h1rsign eq h0otype )
          FOR ALL ENTRIES IN lt_st_p1
          WHERE h1otype EQ 'O' AND h1sobid = lt_st_p1-sobid
          AND h1plvar EQ lv_plan_version AND h1relat EQ '003'
          AND h1rsign EQ 'B' AND h1istat EQ '1' AND h1subty EQ 'B003' AND h1sclas EQ 'S'
    I want to get the stext of the braNCH. THE lt_st_p1 is having the emp id and position. and i want to get branch , position and stext( of branch) in lt_st_p1_temp by the help of join. I am implementing this qauery, but is getting subrc 4, what is the problem in this , please rectifuy if any problem found ?

    You may want to change:
    check lt_st_p1 is not INITIAL.
    to
    check lt_st_p1[] is not INITIAL.
    This depends on whether or not the internal table was defined with a header line.
    Rob
    Edited by: Rob Burbank on Jan 2, 2012 2:45 PM

  • CIN - with TAXINJ and "condition based excise determination"

    Dear All,
    Can I use TAXINJ with "condition based excise determination" for CIN implemenation. We already have TAXINJ and some plants are already working on it.
    If anyone already using the same, please share the problems faced / experience.
    Actually I done settings for above scenario, but while GRN I am getting Message as " BED, AED and SED for the excise item is zero". And BED not getting populated while doing GRn.
    I have created a tax code "C1" and assigned to company code.
    THen I have maintained condition record for JMOP in FV11 for BED. ALso settings done J1ID.
    PO is created with this tax code C1, taxes are getting calculated when
    checked at Invoice tab at PO.
    But while making GRN message comes "BED, AED and SED for the excise
    item is zero" and excise values dont shows at excise tab in MIGO
    Regards

    Go through
    https://wiki.sdn.sap.com/wiki/display/ERPLO/CIN+Configuration
    and
    http://help.sap.com/saphelp_47x200/helpdata/en/09/ebf138cdd78a4be10000000a114084/frameset.htm
    Hope you will get good idea

Maybe you are looking for

  • How to get sub and grand total

    Dear all, I have a report which combines the two totals together and and makes one formula. This formula then is filtered according to Group2 (Reason Code). Group 1 is the same Reason Code however with Specified names. Group2 is the same reason code

  • InDesign generated 'Press Ready' PDF files

    I have always prepared images (300dpi resize & CMYK conversion) in Photoshop and imported them into Indesign.  Is this even necessary now? Does a 'Press Ready' PDF generated from InDesign do all of this? I understand that if an image is low res to st

  • Scheduled a webi report and set it send to EMAIL.

    Our customer found when they scheduled a webi report and set it send to EMAIL, it will cost much more time than usual after they have their SIA restarts. The first time it takes 4-5 times longer to receive a report in mailbox than next time onwards.

  • Freight information reprot

    Hi, I need to create a report to find tOTAL FREIGHT CHARGES IN, TOTAL FREIGHT CHARGES OUT, TOTAL FREIGHT INVOICED. FOR a particular sales org. Will VBRK-KNUMV and  KONV-KWERT will work or do i need more table. If you can specify the field that will b

  • Calling two transaction in one Zprogram

    How to call two transaction (MIGO and MIRO)with each transaction should display two different window simultaneously from one Zprogram.. Pls let me know ...