Hi,
I download OpenJPA2.0 and try to use Criteria Query, and I download JPA2.0
Spec final release document form jcp.org
At page 263, it wrote this:
CriteriaBuilder cb = ...
CriteriaQuery<String> q = cb.createQuery(String.class);
Root<Customer> customer = q.from(Customer.class);
Join<Customer, Order> order = customer.join(Customer_.orders);
Join<Order, Item> item = order.join(Order_.lineItems);
q.select(customer.get(Customer_.name))
.where(cb.equal(item.get(Item_.product).get(Product_.productType),
"printer"));
and I try it like this
@Test
public void testCriteriaQueryJoins(){
EntityManager em = entityManagerProvider.get();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Corporation> q = cb.createQuery(Corporation.class);
Root<Corporation> corporation = q.from(Corporation.class);
Join<Corporation, Division> division =
corporation.join(Corporation_.divisions);
Join<Division, Department> department =
division.join(Division_.departments);
q.select(corporation.get(Corporation_.name))
.where(cb.equal(department.get(Department_.division).get(Division_.name),
DIVISION_NAME));
TypedQuery<Corporation> tq = em.createQuery(q);
List<Corporation> result = tq.getResultList();
assertThat(result, notNullValue());
for (Corporation c : result){
System.out.println(c.getName());
}
em.clear();
}
But there is something wrong in this example.
At this line q.select(corporation.get(Corporation_.name)), and Eclipse tell
me that: the select method is wrong, and advise me to use multiselect(...)
instead
Is my code wrong? or document wrong? or some other wrong?
Thanks,
Zhanming.
--
View this message in context:
http://openjpa.208410.n2.nabble.com/JPA2-0-Criteria-API-question-select-tp5094119p5094119.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.