For example JPA Criteria API can be used without generated metamodel. Type safety is lost, but I can create query without prior knowledge of data model using only reflection at runtime. I would like to use Querydsl in the same way. I don't care about type safety since I don't know data model up front anyway.
On my recent project I'd like to use Querydsl mainly because it constitutes another layer over persistence. So I can hopefully use same queries over JPA, JDO, JDBC, Lucene, Hibernate Search, MongoDB, Collections and RDFBean.
Or is there any alternative to Querydsl which can be used in described way?
Since NoSQL DBs are on the rise. Is there any other framework which constitutes similar abstract layer over various persistence providers?
Subqueries To create a subquery you create a JPASubQuery instance, define the query parameters via from, where etc and use unique or list to create a subquery, which is just a type-safe Querydsl expression for the query. unique is used for a unique (single) result and list for a list result.
Querydsl is an extensive Java framework, which allows for the generation of type-safe queries in a syntax similar to SQL. It currently has a wide range of support for various backends through the use of separate modules including JPA, JDO, SQL, Java collections, RDF, Lucene, Hibernate Search, and MongoDB.
Querydsl is a framework that enables the construction of statically typed SQL-like queries through its fluent API. Spring Data modules offer integration with Querydsl through QuerydslPredicateExecutor .
Predicate is the common interface for Boolean typed expressions.
There are two ways to use Querydsl without a generated metamodel.
The first way is to construct your expressions manually http://www.querydsl.com/static/querydsl/2.9.0/reference/html/ch03.html#d0e1379
and the second is to use the Alias functionality of Querydsl http://www.querydsl.com/static/querydsl/2.9.0/reference/html/ch02s07.html
The Querydsl queries share common interfaces and look alike, but you can't use the same queries over different persistence types directly, since Querydsl doesn't provide any query abstraction across modules.
Individual parts of queries can be shared, such as predicates or projections, but queries are tied to a certain module.
What you can do is to stick to one of the common persistence abstractions JPA or JDO, and use RDBMS, OODB and NoSQL engines via them.
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