Zhanming, Have you generated metamodel classes (<EntityName>_.java) for your entities? This section of the OpenJPA manual explains how to generate them.
http://openjpa.apache.org/builds/2.0.0/apache-openjpa-2.0.0/docs/manual/manual.html#d0e11088 -Jeremy On Mon, May 24, 2010 at 1:37 PM, Kevin Sutter <[email protected]> wrote: > Hi, > Your example looks okay to me. Your selection is singular. There should > be > no reason for the multiselect. Maybe Eclipse is complaining about a > problem > that doesn't exist. Which Eclipse are you using? And, did you > re-configure > your Eclipse environment to be using OpenJPA instead of EclipseLink? Does > your example compile cleanly outside of Eclipse? Maybe somebody else can > spot an error in your example, but it looks like it should work. > > Kevin > > On Mon, May 24, 2010 at 9:46 AM, Zhanming Qi <[email protected]> wrote: > > > > > 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. > > >
