views:

207

answers:

1

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?

A: 

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

GaryF
Thanks! This works correctly
Joopiter