nerdexam
Oracle

1Z0-898 · Question #61

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…

The correct answer is D. CriteriaQuery <office> cq = cb.createQuery (Office.class). Example 1: (not B, not C) CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Example 2: (not A) The following query retrieves all the Country objects in the database. Because multiple result objects are expected, the query should be run using the getResultList method…

Criteria API

Question

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.

Options

  • ACriteriaQuery <office> cq = cb.createQuery (Office.class); . . .
  • BCriteriaQuery cq = cb.createQuery (Office.class)
  • CCriteriaQuery<office> cq = em.createQuery (cq, office.class); . . .
  • DCriteriaQuery <office> cq = cb.createQuery (Office.class); . . .

How the community answered

(45 responses)
  • A
    7% (3)
  • B
    13% (6)
  • C
    2% (1)
  • D
    78% (35)

Explanation

Example 1: (not B, not C) CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Example 2: (not A) The following query retrieves all the Country objects in the database. Because multiple result objects are expected, the query should be run using the getResultList method: TypedQuery<Country> query = em.createQuery("SELECT c FROM Country c", Country.class); List<Country> results = query.getResultList();

Topics

#TypedQuery#CriteriaQuery#type-safe query#CriteriaBuilder

Community Discussion

No community discussion yet for this question.

Full 1Z0-898 Practice