Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
982 views
in Technique[技术] by (71.8m points)

jpa - How to join an entity and a custom select using CriteriaBuilder

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!

question from:https://stackoverflow.com/questions/66066826/how-to-join-an-entity-and-a-custom-select-using-criteriabuilder

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...