Probably the guys who write documentation are very sleepy all the time, since it is not clear why everything always ends at half the example. Here is an example from the docks, like an example, and on the other hand a piece of stupid, unfinished code:
CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Metamodel m = em.getMetamodel(); EntityType<Pet> Pet_ = m.entity(Pet.class); EntityType<Owner> Owner_ = m.entity(Owner.class); Root<Pet> pet = cq.from(Pet.class); Join<Owner, Address> address = cq.join(Pet_.owners).join(Owner_.addresses);
Well, they wrote how to call a join, and what to do with it? What is the address? What kind of person is that? Where to put it? HOW TO POINT BY WHAT AREA DO I WANT TO MAKE A JOIN? Or is this interface endowed with intelligence and he himself knows how and by what field when to join? Who faced type-safe queries and joins, give an example of how to finish writing a full join request to indicate that I want to join the field, because I no longer have the strength to play these riddles and guesswork with documentation of hibernates.
Update 1 : Just that I found an example with the construction of records in the criteria, off the docks hibernate.
Example 9.10. Example with Collections
CriteriaQuery<Person> personCriteria = builder.createQuery( Person.class ); Root<Person> personRoot = person.from( Person.class ); Join<Person,Order> orders = personRoot.join( Person_.orders ); Join<Order,LineItem> orderLines = orders.join( Order_.lineItems );
This is all ... this is all an example. Wonderful. Why is it needed? What did I learn from him? Yes, I did not know. This is just half of the unfinished code. Maybe someone has a decent source where you can study type-safe queries?
Update 2 : The answer to the question if someone will have difficulty creating type-safe queries using JOIN.
@Override public List<Menu> getAllFromPlace(Long id){ CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Menu> query = builder.createQuery(Menu.class); Root<Place> root = query.from(Place.class); Join<Place,Menu> menu = root.join(Place_.menus); query.select(menu).where(builder.equal(root.get(Place_.id), id)); List<Menu> menus = em.createQuery(query).getResultList(); return menus; }