Q:

Equivalent criteria or HQL?

I have below SQL query. what is the equivalent Criteria or HQL query?
select max(id) from 
(
select max(id) id from TableA
union 
select max(id) from TableB
)

Thanks!

A:

There is no equivalent, because there is no UNION in HQL or Criteria. Some workarounds are:

use native query
build view and map it for read only purposes (if it for some reason really not possible to use native query)
perform two queries and choose in Java code which value to use.

