Selecting specific columns in jpa 2 API?

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

The following is an SQL job:

    SELECT column1, column2 FROM MyTableThatHasMultipleColumns

With the Hibernate Criteria API, this can be done using Projections, is there an equivalent specification specification JPA 2?

+5
source share
1 answer

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

The select () method determines the result of the request. If this parameter is not specified, the selection projection is considered an object of the root domain. However, you can explicitly specify the selected projections as a list:qdef.select(customer.get(Customer_.name), order.get(Order_.status));

+6
source

All Articles