0

I need to convert a certain query to JPA using CriteriaBuilder. The query looks like this:

SELECT *
FROM ENTITY1 a
INNER JOIN (
    SELECT *
    FROM ENTITY2 b
    where b.STARTDATE = '2019-10-31T00:00:00.000+0100'
) ON ENTITY2.ID = ENTITY1.ENTITY2_ID

Before you ask: for the sake of performance, I wish to avoid converting the query to:

SELECT *
FROM ENTITY1 a
INNER JOIN ENTITY2 b ON ENTITY2.ID = ENTITY1.ENTITY2_ID
where b.STARTDATE = '2019-10-31T00:00:00.000+0100'

Indeed, both ENTITY1 and ENTITY2 contain such a huge lot of rows, even with the right indexes, executing the latter version of the query takes an unacceptable amount of time.

Now, I'm at a loss how to implement the former version with JPA. Any hint would be appreciated!

  • For the sake of performance for answering, please show the stuff you tried with CriteriaBuilder? All this seems like JPQL or maybe native? – pirho Feb 05 '21 at 18:41
  • better edit your question rather than add efforts in comments – pirho Feb 09 '21 at 17:29
  • Thank you for the advice. Right now, I realize I have too few useful elements to add to my question. I'll edit it when that changes. – Benoît Smith Feb 10 '21 at 23:25

0 Answers0