This is the SQL query that I need Hibernate to build (executed in my sql client tool runs really fast):
select decision.decisionid from Decision decision
INNER JOIN Proceeding proceeding on decision.proceedingId=proceeding.proceedingId
INNER JOIN IPRIGHT_PROCEEDING ipright on proceeding.proceedingId=ipright.proceedingId
where proceeding.dossierkindcode=7 and decision.creationdate>=TO_DATE('2017-04-22','YYYY-MM-DD') and decision.creationdate<=TO_DATE('2017-04-27','YYYY-MM-DD') or decision.updatedate>=TO_DATE('2017-04-22','YYYY-MM-DD') and decision.updatedate<=TO_DATE('2017-04-27','YYYY-MM-DD')
This is the HQL code that I wrote:
@Query( "select decision.decisionId FROM Decision decision, Proceeding proceeding, IprightProceeding iprightproceeding"
+ " INNER JOIN decision.proceeding"
+ " INNER JOIN iprightproceeding.proceeding"
+ " WHERE decision.proceeding.dossierKind = ?1"
+ " AND decision.creationDate>=?2"
+ " AND decision.creationDate<=?3"
+ " OR (decision.updatedate>=?2 AND decision.updatedate<=?3)"
This is the awful query that is generating, that takes so much time that even blocks completely the server.
Hibernate: select decision0_.decisionid as col_0_0_ from DECISION decision0_
inner join PROCEEDING proceeding3_ on decision0_.proceedingid=proceeding3_.proceedingid
cross join PROCEEDING proceeding1_
cross join IPRIGHT_PROCEEDING iprightpro2_
inner join PROCEEDING proceeding4_ on iprightpro2_.proceedingid=proceeding4_.proceedingid
where proceeding3_.dossierkindcode=? and decision0_.creationdate>=? and decision0_.creationdate<=? or decision0_.updatedate>=? and decision0_.updatedate<=?
As you see, its event joining twice the same table!!!
Could you help me please?
Thanks
First, I think you wrote JPQL code, not HQL, but in any case your query has a number of problems. First, look at your SELECT
:
select decision.decisionId
FROM Decision decision, Proceeding proceeding, IprightProceeding iprightproceeding
You are doing a cross join between these three tables, because there is effectively no join condition specified. You need to restrict the join in the WHERE
clause of the JPQL. Without doing that, it is a cross join.
On top of this , you are then doing a series of inner joins to the same tables, resulting in second joins for some of the tables. Try the following JPQL query, which may not be perfect, but should be closer to what you intend to run.
select d.decisionId FROM Decision d, Proceeding p, IprightProceeding i
where d.proceeding = p and
p.proceedingId = i and
d.proceeding.dossierKind = ?1 and
d.creationDate >= ?2 and
d.creationDate <= ?3 or
(d.updatedate >= ?2 AND d.updatedate <= ?3)
JPQL syntax has a flavor all its own and differs from ANSI SQL in a number of ways.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.