JPQL union and Join

This JPQL doesn’t work as expected what did I do wrong?

SELECT distinct ec.event FROM callbook$EventCard ec FULL OUTER JOIN callbook$Event e ON = where is null 
SELECT distinct ec.event FROM callbook$EventCard ec FULL OUTER JOIN callbook$Event e ON = WHERE <> :session$currentMemberID

I want it to act same way as this plain sql:
And also I want to clarify: what exactly is used in Cuba: JPA, hibernate, or ECLIPSELINK Or it depends on component? Oh it seems to be ECLIPSELINK but why doesn’t it then say “Union is not supported” error?

I don’t think JPQL supports UNION command. Here is an article I sometimes refer to when I’m trying to do something in JPQL.

Perhaps you can execute two queries and merge the results in Java? Or run a SQL query?

1 Like

Thanks Keith, but how do you think: is each of the two queries itself correct? (Behave the same as the original native query)?
Turned out it’s eclipseLink which supports UNION
I used “custom Datasource” where I did whatever I wanted in Java and returned Collection but the problem in that approach is that fts (filter and some other features probably) don’t work with such Datasources (without query)… It seemed to me that Ds.commit didn’t work…

The problem seems that my entities are somehow unrellated But I don’t quite understand how should they be related…

I also don’t understand why
SELECT e FROM callbook$Event e
works and
SELECT ec.event FROM callbook$EventCard ec where <> :session$currentMemberID
works but
SELECT e FROM callbook$Event e UNION SELECT ec.event FROM callbook$EventCard ec where <> :session$currentMemberID
doesn’t? Causes error: Query argument session$currentMemberID not found in the list of parameters provided during query execution

Wow on Russian forum i’s said that union is not supported at all by cuba Maybe “union all” was meant? Waiting comments from cuba authors

Yes, that is interesting. I’m sorry I can’t confirm with certainty the ability to do UNION. I hope someone can jump in and clarify. It is the feature I miss most from SQL.

I’ve been thinking about the custom datasource approach. It does seem tough without a single query. But is it possible to have a single query that grabs too much but override the getEntities method to filter out the results that your union logic would have taken care of? I’m not sure of volumes and performance conditions… You would need to override getCount too… Just a wild idea.

Unfortunately, JPA specification doesn’t support UNION statement in JPQL. CUBA only works with JPQL defined in the JPA specification.

I paraphrased this question here JPQL select from association recipe2 - CUBA.Platform