Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting specific columns in jpa 2 Criteria API?

Is there a way to select specific column using the JPA 2 Criteria API?

The following is the target SQL Statement:

    SELECT column1, column2 FROM MyTableThatHasMultipleColumns

With Hibernate's Criteria API this can be done using Projections, is there an equivalent to the JPA 2 Criteria Specification?

like image 238
Joopiter Avatar asked Aug 13 '10 11:08

Joopiter


1 Answers

Yes, it does. The select() method is what you need to use. From the openJPA manual:

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

like image 73
GaryF Avatar answered Sep 27 '22 16:09

GaryF