1Z0-898 · Question #62
A developer is writing an application with three java Persistence API entities: order, customer, and Address. There is a many-to-one relationship between order and customer, and a one to- many…
The correct answer is A. String postalCode = . . . D. String postalCode =. A: Join Order and Customer and join Customer and Address. Works fine. Not B: Chained joined not set up correctly. C: Join Order and Address through first joining Order and Customer. Not D: Cannot Join Order Address it just one single join. Need to chain the join. Note:Querying…
Question
A developer is writing an application with three java Persistence API entities: order, customer, and Address. There is a many-to-one relationship between order and customer, and a one to- many relationship between customer and Address. Which two Criteria queries will return the orders of all customers who have an address whose value specified by the String parameter postalcode? (Choose two)
Options
- AString postalCode = . . .
- BString postalCode = . . .
- CString postalCode = ...
- DString postalCode = ...
How the community answered
(59 responses)- A80% (47)
- B7% (4)
- C14% (8)
Explanation
A: Join Order and Customer and join Customer and Address. Works fine. Not B: Chained joined not set up correctly. C: Join Order and Address through first joining Order and Customer. Not D: Cannot Join Order Address it just one single join. Need to chain the join. Note:Querying Relationships Using Joins For queries that navigate to related entity classes, the query must define a join to the related entity by calling one of the From.join methods on the query root object or another join object. The join methods are similar to the JOIN keyword in JPQL. The target of the join uses the Metamodel class of type EntityType<T> to specify the persistent field or property of the joined entity. The join methods return an object of type Join<X, Y>, where X is the source entity and Y is the target of the join. In the following code snippet, Pet is the source entity, Owner is the target, and Pet_ is a statically generated metamodel class: CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Root<Pet> pet = cq.from(Pet.class); Join<Pet, Owner> owner = pet.join(Pet_.owners); Joins can be chained together to navigate to related entities of the target entity without having to create a Join<X, Y> instance for each join: CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Root<Pet> pet = cq.from(Pet.class); Join<Owner, Address> address = cq.join(Pet_.owners).join(Owner_.addresses);
Topics
Community Discussion
No community discussion yet for this question.