编程语言
首页 > 编程语言> > java – 在jpa 2 Criteria API中选择特定列?

java – 在jpa 2 Criteria API中选择特定列?

作者:互联网

有没有办法使用JPA 2 Criteria API选择特定列?

以下是目标SQL语句:

    SELECT column1, column2 FROM MyTableThatHasMultipleColumns

使用Hibernate的Criteria API,这可以使用Projections完成,是否与JPA 2 Criteria Specification相当?

解决方法:

是的,它确实. select()方法是您需要使用的方法.从openJPA手册:

The select() method defines the result of the query. If left unspecified, the select projection is assumed to be the root domain object. However, you can specify the selected projections explicitly as a list: qdef.select(customer.get(Customer_.name), order.get(Order_.status));

标签:java,orm,hibernate,jpa-2-0,criteria-api
来源: https://codeday.me/bug/20190518/1129731.html