How can I create SELECT FROM SELECT query with JPA and Hibernate?

Hello. I need create query

FROM (SELECT ...) alias
WHERE alias.SomeProperty = someValue AND alias.OtherProperty = otherValue

But QueryOver.WithSubquery creates query SELECT * FROM table WHERE someProperty = (SELECT …)

Help me please

Neither JPQL or Criteria supports derived tables. Just use the native SQL which allows you to benefit from any database-specific feature or syntax.

Just recently Jan-Willem Gmeilig Meyling was introduced on the Hibernate blog who wrote about exactly that use case and how Blaze-Persistence’s support for CTEs can help you with this:

See here for examples: