UNION to JPA Query

前端 未结 7 921
日久生厌
日久生厌 2020-12-01 15:57

Is it possible to query \"UNION\" in JPA and even \"Criteria Builder\"?

I\'m looking for examples, but so far i got no result.

Does anyone have any examples

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 16:16

    One thing just comes to my mind (searching for the exact same problem):

    Perform two different JPA queries on the same entity mapping and simply add the objects of the second result to the list (or set to avoid duplicates) of the first result.

    That way you get the same effect as with a UNION, the difference being that you use two SQL statements instead of one. But actually, I would expect that to perform just as good as issueing one UNION statement.

提交回复
热议问题