3
How can I do an associative table search ? There are two entities, Pessoa and Time. Where I came from the Personal association_time that has id_person and id_time.
My goal is to list all the id_time of a certain id_person
Following error:
HTTP Status 500 - org.hibernate.hql.ast.QuerySyntaxException: pessoa_time is not mapped [select t from pessoa_time u where u.id_pessoa = :pPessoa]
Personal:
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;
}
Personal:
public void listarmeustimes(){
getDao().listarmeustimes(getPessoa());
}
Pessoa 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;
Submitted the following error: HTTP Status 500 - org.hibernate.hql.ast.Querysyntaxexception: Unexpected token: * near line 1, column 8 [select * from pessoa_time]
– Rafael Augusto
@Rafaelaugusto I made a modification in consultation. I edited the answer. See if it works.
– Sandro Queiroz Jr