Let say i have model called Employee with 70 column. How can i implement query
SELECT id from t_employee in spring + querydsl without modifying lot of code from this code.
BooleanExpression paramEmployee = qEmployee.company.id.eq(new Long(data.get("company").toString()));
Iterable<Employee> employeeReportIterable =employeeRepository.findAll(paramEmployee);
If You want to use QueryDSL predicate and have single attribute response you could use just QueryDSL directly without using spring-data.
// where entityManager is a JPA EntityManager
JPAQuery<?> query = new JPAQueryFactory(entityManager);
BooleanExpression paramEmployee = qEmployee.company.id.eq(new Long(data.get("company").toString()));
List<Long> id = query.select(qEmployee.id).from(qEmployee).where(paramEmployee).fetch();
I'm afraid querydsl integration with spring only allows for construction of dynamic predicates and not full queries as indicated per spring data documentation.
I suppose though you could just use the getId() method from your Employee class without modifying the code.
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