java - How to specify multiple conditions on left join using JPA Criteria API? -


I would like to change the following SQL query:

  from region_tree Country * Choose country Exclude external area area_tree area REG_CODE_PAR = Area REG_CODE more area Lft & lt; Country. LFT and field. RGT & gt; Country. Arjiti area .REG_CODE_PAR = 'ALL' and COUNTRY.STATUS_CODE = 'A' and REGION.STATUS_CODE = 'A  

The JPA Krotiria based query.

I applied a unit created:

  @ Antiti @Table (name = "REGION_TREE") public class field Siriyljbl to represent the joining self {. .. Some other features @ManyToOne @JoinColumn (name = "REG_CODE_PAR") private sector area; ... getters and setters}  

I JPA query to make use of the following code

  Criteriabuilder cb = em.getCriteriaBuilder (for); CriteriaQuery & LT; RegionTree & gt; Cq = cb.createQuery (area category); The root of the & lt; RegionTree & gt; E = cc From (Area Tree); & Lt; Region Region, Region & gt; Join R = E.John ("Area", Joint Type, LEFT); P1 = cb.greaterThan (Ikjiktik ( "LFT"). As (Puarnankkclas), as Arkjiktik ( "LFT"). (Puarnankkpat)); As P2 = cb.lessThan (EGT ("RGT") (integer .clash), RGT ("RGT"). (As integer class)); P3 = cb.equal (e.get ("statusCode"), "A"); P4 = cb.equal (r.get ("statusCode"), "A" Predicate;); P5 = cb.equal (r.get ("regCodePar"), "All"); Cq.where (P1, P2, P3, P4, P5); TypedQuery & LT; RegionTree & gt; Tq = em.createQuery (cq); L = tq.getResultList (); ` 

This is a query generated by Hibernate, when I run this part of the code.

  select regiontree0_.REG_CODE REG1_7_, as well as regiontree0_.LFT LFT7_, regiontree0_.NAMENAME NAME7_, REG4_7_ as regiontree0_.REG_CODE_PAR, RGT7_ as regiontree0_.RGT, Regiontree0_.STATUS_CODE REGION_TREE field STR02 left as STATUS6_7_ in outer area REGION_TREE regiontree1_ at regiontree0_.REG_CODE_PAR = regiontree1_.REG_CODE where cast (regional block as integer 0.L.F.) & gt; Cast (area block as integer 1). And cast (area .0gg as integer) & lt; Cast (area 1). RGT as integer and area .00 .. STATUS_CODE =? And regiontree1_.STATUS_CODE =? And regiontree1_.REG_CODE_PAR =? I have tried in several ways in which the code's code  cq.where  has been removed but the generated query can not match my original one. Have I configured something wrong? 

Try cq.select (r); last cq.from () call is used as the result of the result without cq.select () after joining.


Comments