-
Notifications
You must be signed in to change notification settings - Fork 2
QueryDSL
Edmo Vamerlatti Costa edited this page Apr 13, 2018
·
4 revisions
EntityManager em = ...;
String query = "select name, age where age > 18 order by name limit 0, 100";
JPAQueryDslParser parser = new JPAQueryDslParser(em);
//Create a evaluation context. All paths added here will be available on query syntax
QueryDslContext context = QueryDslContext.from(QTest.test)
.withPath("name", QTest.test.name)
.withPath("age", QTest.test.age)
.withPath("other.id", QTest.test.other.id)
.withPath("other.name", QTeste.test.other.name)
.build();
//Parse query string into a QueryDSL JPAQuery object
JPAQuery jpaQuery = parser.parse(query, context);
//List only projected fields
List<Test> list = jpaQuery.list(context.getProjectionOrDefault());