1Z0-898 · Question #25
A user entity is in a one-to-many relationship with a Book entity. In other words, a developer reach the collection of books that a user instance myUser has by using the path expression- "myuser…
The correct answer is A. SELECT u FROM User U WHERE SIZE (u.books) = 2 C. SELECT u FROM User u (WHERE COUNT (b) FROM u.books b) = 2. A (not D):The SIZE(collection) function returns the number of elements in a specified collection. SIZE(c.languages) is evaluated to the number of languages in that collection. C: Example(the aggregate query returns a Long): Query q2 = em.createQuery( "SELECT COUNT(e) FROM…
Question
A user entity is in a one-to-many relationship with a Book entity. In other words, a developer reach the collection of books that a user instance myUser has by using the path expression- "myuser - books". A developer wants to write a Java Persistence query that returns all users that have only two books. Which two are valid queries that return this information? (Choose two.)
Options
- ASELECT u FROM User U WHERE SIZE (u.books) = 2
- BSELECT u FROM User WHERE COUNT (u.books) = 2
- CSELECT u FROM User u (WHERE COUNT (b) FROM u.books b) = 2
- DSELECT u FROM user u WHERE (SELECT SIZE (b) FROM u.books b) = 2
How the community answered
(51 responses)- A80% (41)
- B8% (4)
- D12% (6)
Explanation
A (not D):The SIZE(collection) function returns the number of elements in a specified collection. SIZE(c.languages) is evaluated to the number of languages in that collection. C: Example(the aggregate query returns a Long): Query q2 = em.createQuery( "SELECT COUNT(e) FROM Employee e WHERE e.salary > :limit");
Topics
Community Discussion
No community discussion yet for this question.