QueryDSL未返回该对象

时间:2014-03-25 16:54:27

标签: java spring-data querydsl

我遇到查询dsl的问题。我已经生成了querydsl类。但是当我尝试进行查询时,它不返回Customer类型的结果对象,而是返回实际的sql查询。我做错了什么?

@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();

}

}

1 个答案:

答案 0 :(得分:4)

我认为你错过了uniqueResult(或多个结果list()

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

请参阅:http://www.querydsl.com/static/querydsl/2.1.0/reference/html/ch02.html