Which of the following Criteria query snippets demonstrates the correct way to create and execute strongly typed queries? Assume that cb references an instance of the CriteriaBuilder interface and em references an EntityManager instance.
A.
CriteriaQuery <office> cq = cb.createQuery (Office.class);
. . .
TypedQuery<Office> tq = em.ceateQuery (cq) ; L
1st <office> offices = tq.getResultList ();
B.
CriteriaQuery cq = cb.createQuery (Office.class)
. . .
TypedQuery<office> tq = em.createQuery (cq, office.class);
List <office> offices = tq.getresult ();
C.
CriteriaQuery<office> cq = em.createQuery (cq, office.class);
. . .
TypedQuery<Office> tq = em.createQuery (cq);
List <office> offices = tq.getresult ();
D.
CriteriaQuery <office> cq = cb.createQuery (Office.class);
. . .
TypedQuery<Office> tq = em.ceateQuery (cq);
List<office> Offices = tq.getResultList ();
Explanation:
http://stackoverflow.com/questions/3424696/jpa-criteria-api-how-to-add-join-clause-as-general-sentence-as-possible
A and D the same
if we changed D to be like this
CriteriaQuery cq = cb.createQuery ();
. . .
TypedQuery tq = em.ceateQuery (cq);
List Offices = tq.getResultList ();
what happen?
A and D the same
TypedQuery typedQuery = em.createQuery(criteriaQuery);
List result = typedQuery.getResultList();
CriteriaQuery c = cb.createQuery(Office.class); //1
Root office = c.from(Office.class); //2
c.select(office); //3
TypedQuery q = em.createQuery(c); //4
List returnValue = q.getResultList(); //5
syntax of correct code