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 of how to use it?
Or would that be with native sql?
SQL supports UNION, but JPA 2.0 JPQL does not. Most unions can be done in terms of joins, but some can not, and some are more difficult to express using joins. EclipseLink supports UNION.
Native query refers to actual sql queries (referring to actual database objects). These queries are the sql statements which can be directly executed in database using a database client.
SQL supports UNION, but JPA 2.0 JPQL does not. Most unions can be done in terms of joins, but some can not, and some are more difficult to express using joins.
EclipseLink supports UNION.
Depending on the case, one could use sub queries, something like:
select e from Entity e where e.id in ( select e.id from Entity2 e2 join e2.entity e where e2.someProperty = 'value' ) or e.id in ( select e.id from Entity3 e3 join e3.entity e where e3.someProperty = 'value2' )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With