Question

I'm having a problem with query dsl. I have generated the querydsl classes. But when I try to do a query, it is not returning a result object of type Customer, but rather it is returning the actual sql query. What am I doing wrong?

@Configuration
@EnableAutoConfiguration
public class App
{
    public static void main( String[] args )
    {

        ConfigurableApplicationContext context = SpringApplication.run(App.class);
        CustomerRepository repository  = context.getBean(CustomerRepository.class);

        repository.save(new Customer("Alicia", "Keys"));

        QCustomer customer = QCustomer.customer;
        EntityManager em = context.getBean(EntityManager.class);
        JPAQuery query = new JPAQuery(em);

        Customer alicia = query.from(customer).where(customer.id.eq(1L));

        context.close();

}

}

Was it helpful?

Solution

I think you miss uniqueResult (or list() for multiple results)

query.from(customer)
   .where(XXX)
   .uniqueResult(customer);

See : http://www.querydsl.com/static/querydsl/2.1.0/reference/html/ch02.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top