Esempio n. 1
0
 @Test
 public void testQueryKey() {
   XCriteriaBuilder cb = this.getEntityManager().getCriteriaBuilder();
   XCriteriaQuery<String> cq = cb.createQuery(String.class);
   XRoot<Computer> computer = cq.from(Computer.class);
   cq.where(cb.equal(computer.get(Computer_.id), 1L));
   cq.select(computer.join(Computer_.cpus).key());
   List<String> keys = this.getEntityManager().createQuery(cq).getResultList();
   Assert.assertEquals(2, keys.size());
   Assert.assertEquals("first-cpu", keys.get(0));
   Assert.assertEquals("second-cpu", keys.get(1));
 }
Esempio n. 2
0
 @Test
 public void testQueryValue() {
   XCriteriaBuilder cb = this.getEntityManager().getCriteriaBuilder();
   XCriteriaQuery<CPU> cq = cb.createQuery(CPU.class);
   XRoot<Computer> computer = cq.from(Computer.class);
   cq.where(cb.equal(computer.get(Computer_.id), 1L));
   cq.select(computer.join(Computer_.cpus).value());
   List<CPU> values = this.getEntityManager().createQuery(cq).getResultList();
   Assert.assertEquals(2, values.size());
   Assert.assertEquals(1L, values.get(0).getId().longValue());
   Assert.assertEquals("Intel Core-i5", values.get(0).getName());
   Assert.assertEquals(2L, values.get(1).getId().longValue());
   Assert.assertEquals("Intel Core-i7", values.get(1).getName());
 }