0
I have the Personal class which has the following method:
public List<Pessoa> BuscarTodos() {
List<Pessoa> list = null;
EntityManager em = getEM();
try {
list = em.createQuery("select t from Pessoa t").getResultList();
} catch (HibernateException e) {
System.out.println(e.toString());
} finally {
em.close();
}
return list;
}
And in my Servlet, I have the following doGet:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PessoaDAO<Pessoa> db = new PessoaDAO<Pessoa>();
try {
List<Pessoa> list = db.BuscarTodos();
req.setAttribute("list", list);
getServletContext().getRequestDispatcher("/index.jsp").forward(req, resp);
System.out.println(req.getAttribute("list"));
} catch (Exception e) {
e.printStackTrace();
}
}
'Cause when I give a sysout, it shows up like this:
[model. Person@7d5d4b78, model.Person@1eb15301, model.Person@15f8c5af]
And not the list itself?
If it helps, this is class person:
@Entity
public class Pessoa {
@Id
@GeneratedValue
@Column(name="ID")
private int id;
@Column(name="NOME")
private String nome;
@Column(name="CPF")
private String cpf;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
}
Likely duplicate of How do I display what’s inside the list?
– user28595
One more: Doubts about the toString() method of the Object class
– user28595
Show.. already got the answers in these links.. thank you very much!
– maiconfriedel