Course course2 = newCourse("Not Biology");
Course course3 = newCourse("Biology");
Course course4 = newCourse("Not Biology");
Course course5 = newCourse("Biology");
Course course6 = newCourse("Not Biology");
Student student = newStudent(10, course1, course2);
Student student2 = newStudent(11, course3, course4);
Student student3 = newStudent(10, course5, course6);
beginTxn();
em.persist(student);
commitTxn();
beginTxn();
em.persist(student2);
commitTxn();
beginTxn();
em.persist(student3);
commitTxn();
beginTxn();
Query q = em.createQuery(
"select from " + Student.class.getName() + " s JOIN s.courses c where "
+ "c.department = 'Biology' and "
+ "s.grade = 10");
q.setFirstResult(1);
assertEquals(student3.getId(), ((Student) q.getSingleResult()).getId());
q = em.createQuery(
"select from " + Student.class.getName() + " s JOIN s.courses c where "
+ "c.department = 'Biology' and "
+ "s.grade = 10");
q.setFirstResult(2);