I got class:
@Entity
@Table(name="restaurants")
public class Restaurant {
@Id
@GeneratedValue
private int id;
private String name;
private String street;
(...)
@ManyToMany
@JoinTable(name="user_restaurant_owner",
joinColumns={@JoinColumn(name="restaurant_id")},
inverseJoinColumns={@JoinColumn(name="username")})
private List<User> owner;
How to get Restaurant if I know User (“owner”) username?
Query q = session.createQuery(“from Restaurant as r where r.owner = :username”).setString(“username”, username);
it doesn;t work
You need to join to a collection in HQL if you are selecting on properties of the element within the collection.