Which of the following Criteria query snippets demonstrates the correct way to create and execute strongly typed queries?

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.

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



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Marian

Marian

A and D the same

shijazi

shijazi

if we changed D to be like this
CriteriaQuery cq = cb.createQuery ();
. . .
TypedQuery tq = em.ceateQuery (cq);
List Offices = tq.getResultList ();

what happen?

Mohamed Fayek

Mohamed Fayek

A and D the same

TypedQuery typedQuery = em.createQuery(criteriaQuery);
List result = typedQuery.getResultList();

Mohamed Fayek

Mohamed Fayek

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

Mohamed Fayek

Mohamed Fayek

syntax of correct code