How to write such a request in Criteria?

SELECT place_id FROM place_has_menu WHERE menu_id=?; 

If our Menu class doesn't know anything about the Place class, then Place has a link to Menu OneToMany, which generates the table itself. How now to write this request, using metamodels?

Update1

 @Entity @Table public class Place { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column private Long id; @JoinColumn(name = "name") private String name; @JoinColumn(name="file") private String file; @ManyToMany(mappedBy="places",cascade = CascadeType.ALL) private Set<PlaceType> placeTypes = new HashSet<PlaceType>(); @ManyToMany(mappedBy="placesToAdministrate", cascade=CascadeType.ALL) private Set<UserAccount> operators = new HashSet<UserAccount>(); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable( name="place_has_menu", joinColumns = {@JoinColumn(name = "place_id")}, inverseJoinColumns = {@JoinColumn(name = "menu_id")} ) private Set<Menu> menus = new HashSet<Menu>(); 

In the classroom menu, I do not have any mention of Place. Is it possible then to configure this connection in the reverse order?

Update2 Answer: The problem in the request was not because the problems were with the hibernate docks, but because I had incorrectly configured entiti, which did not allow me to get data from the table I needed.

    1 answer 1

    It will look like this

     var places = session.createCriteria(Place.class) .add(Restrictions.eq("menu_id", new Integer(2))) .list(); 
    • I use the entity manager, tried to somehow tighten this example, but it does not work. maybe you know how to do this with em? - raviga
    • And what exactly does not work, what errors are you writing? - sp7
    • Well, in this case, this request should return all the Place in which the menu_id field is 2 , something like that. Do you have requests that Hibernate generates are displayed somewhere, for example, in the console or the output of your IDE, in order to see the toli that it was planned to generate? - sp7
    • it turns out that I should have only one Place whose menu_id is 2 . I tried to do it with joins, but this does not work, since in that case I also need the id of the Place itself which I just want to receive - raviga
    • in other words, I only need to get the Menu need to get it from the id Place database and - raviga