How can I search the associative table? There are two entities, Person and Time. From where I created the associative Person_Time that has id_people and id_time.
My goal is to list all the id_time of a certain people_id
Next error:
HTTP Status 500 - org.hibernate.hql.ast.QuerySyntaxException: persona_time is not mapped [select t from persona_time u where u.id_pessoa =: pPeople]
PersonaDAO:
public List<Time> listarmeustimes(Pessoa pessoa) {
Pessoa resultado = new Pessoa();
String consulta = "select t from pessoa_time u where u.id_pessoa = :pPessoa";
Query query = getEm().createQuery(consulta);
query.setParameter("pPessoa", pessoa.getNomeUsuario());
List<Time> meustimes = query.getResultList();
for (Time time : meustimes) {
System.out.println(time.getNome());
}
return meustimes;
}
PersonaBean:
public void listarmeustimes(){
getDao().listarmeustimes(getPessoa());
}
Person Model:
@ManyToMany(mappedBy="listaPessoas")
private List<Time> listaTimes;
Time Model:
@ManyToMany
@JoinTable(name="Pessoa_Time",joinColumns={@JoinColumn(name="id_time")},
inverseJoinColumns={@JoinColumn(name="id_pessoa")})
private List<Pessoa> listaPessoas;